    -- GENERATED by C->Haskell Compiler, version 0.28.8 Switcheroo, 25 November 2017 (Haskell)
    -- Edit the ORIGNAL .chs file instead!

    {-# LINE 1 "./GI/Cairo/Render/Internal/Utilities.chs" #-}
    {-# LANGUAGE FlexibleInstances #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  GI.Cairo.Render.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 GI.Cairo.Render.Internal.Utilities where
    import qualified Foreign.C.String as C2HSImp
    import qualified Foreign.C.Types as C2HSImp
    import qualified Foreign.Ptr as C2HSImp
    import qualified System.IO.Unsafe as C2HSImp

    import GI.Cairo.Render.Types
    {-# LINE 18 "./GI/Cairo/Render/Internal/Utilities.chs" #-}

    import Foreign
    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 33 "./GI/Cairo/Render/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 (Ptr CChar)
    statusToString'_ CInt
    a1' IO (Ptr CChar) -> (Ptr CChar -> 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
    >>= \Ptr CChar
    res ->
      Ptr CChar -> IO String
    C2HSImp.peekCString Ptr CChar
    res IO String -> (String -> 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
    >>= \String
    res' ->
      String -> IO String
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (String
    res')

    {-# LINE 35 "./GI/Cairo/Render/Internal/Utilities.chs" #-}

    version :: (Int)
    version =
      C2HSImp.unsafePerformIO $
      version'_ >>= \res ->
      let {res' = fromIntegral res} in
      return (res')

    {-# LINE 36 "./GI/Cairo/Render/Internal/Utilities.chs" #-}

    versionString :: (String)
    versionString =
      C2HSImp.unsafePerformIO $
      versionString'_ >>= \res ->
      C2HSImp.peekCString res >>= \res' ->
      return (res')

    {-# LINE 37 "./GI/Cairo/Render/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 -> (Ptr CChar -> IO a) -> IO a
    withUTFString Text
    s = ByteString -> (Ptr CChar -> IO a) -> IO a
    forall a. ByteString -> (Ptr CChar -> IO a) -> IO a
    useAsCString (Text -> ByteString
    T.encodeUtf8 Text
    s)

    foreign import ccall safe "GI/Cairo/Render/Internal/Utilities.chs.h cairo_status_to_string"
      statusToString'_ :: (C2HSImp.CInt -> (IO (C2HSImp.Ptr C2HSImp.CChar)))

    foreign import ccall safe "GI/Cairo/Render/Internal/Utilities.chs.h cairo_version"
      version'_ :: (IO C2HSImp.CInt)

    foreign import ccall safe "GI/Cairo/Render/Internal/Utilities.chs.h cairo_version_string"
      versionString'_ :: (IO (C2HSImp.Ptr C2HSImp.CChar))