    -- GENERATED by C->Haskell Compiler, version 0.13.13 (gtk2hs branch) "Bin IO", 27 May 2012 (Haskell)
    -- Edit the ORIGNAL .chs file instead!

    {-# LANGUAGE FlexibleInstances #-}

    {-# LINE 1 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Graphics.Rendering.Cairo.Internal.Utilities
    -- Copyright   :  (c) Paolo Martini 2005
    -- License     :  BSD-style (see cairo/COPYRIGHT)
    --
    -- Maintainer  :  p.martini@neuralnoise.com
    -- Stability   :  experimental
    -- Portability :  portable
    --
    -- http://cairographics.org/manual/Support.html
    -----------------------------------------------------------------------------

    module Graphics.Rendering.Cairo.Internal.Utilities where

    import Graphics.Rendering.Cairo.Types
    {-# LINE 17 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

    import Foreign hiding (unsafePerformIO)
    import Foreign.C
    -- TODO work around cpphs https://ghc.haskell.org/trac/ghc/ticket/13553
    import System.IO.Unsafe (unsafePerformIO)

    import Codec.Binary.UTF8.String
    import Data.Char (ord, chr)
    import Data.Text (Text)
    import Data.ByteString (useAsCString)
    import qualified Data.Text.Encoding as T (encodeUtf8)

    {-# LINE 32 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

    statusToString :: Status -> IO (String)
    statusToString :: Status -> IO String
    statusToString Status
    a1 =
      let {a1' :: CInt
    a1' = Status -> CInt
    forall e i. (Enum e, Integral i) => e -> i
    cFromEnum Status
    a1} in
      CInt -> IO CString
    statusToString'_ CInt
    a1' IO CString -> (CString -> IO String) -> IO String
    forall a b. IO a -> (a -> IO b) -> IO b
    forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
    >>= \CString
    res ->
      peekCString res >>= \res' ->
      Int
    return (res')
    {-# LINE 34 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
    version :: Int
    version =
      let {res = version'_} in
      let {res' = cIntConv res} in
      (res')
    {-# LINE 35 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}
    versionString :: String
    versionString =
      unsafePerformIO $
      let {res = versionString'_} in
      peekCString res >>= \res' ->
      return (res')
    {-# LINE 36 "./Graphics/Rendering/Cairo/Internal/Utilities.chs" #-}

    class CairoString s where
        withUTFString :: s -> (CString -> IO a) -> IO a

    instance CairoString [Char] where
        withUTFString = withCAString . encodeString

    instance CairoString Text where
        withUTFString :: forall a. Text -> (CString -> IO a) -> IO a
    withUTFString Text
    s = ByteString -> (CString -> IO a) -> IO a
    forall a. ByteString -> (CString -> IO a) -> IO a
    useAsCString (Text -> ByteString
    T.encodeUtf8 Text
    s)

    foreign import ccall safe "dist-ghc/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_status_to_string"
      statusToString'_ :: (CInt -> (IO (Ptr CChar)))

    foreign import ccall safe "dist-ghc/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_version"
      version'_ :: CInt

    foreign import ccall safe "dist-ghc/build/Graphics/Rendering/Cairo/Internal/Utilities.h cairo_version_string"
      versionString'_ :: (Ptr CChar)