Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone

Util.CUtil

Contents

Description

Utilities for C wrappers.

  • Functions to convert between haskell and c types.
  • Generic UI debugging functions.

Synopsis

convert

c_rune :: Char -> Word.Word32 Source #

This corresponds to utf8::rune.

c_bool :: Bool -> CChar Source #

bool is C++, not C, so I represent bools as chars.

bytesToCString0 :: ByteString.ByteString -> IO CString Source #

Copy the bytestring to a null-terminated cstring, in malloc'd space. ByteString only has an alloca version of this.

textToCString0 :: Text -> IO CString Source #

Allocate a new UTF8-encoded null-terminated CString.

This copies the string twice, but I think I'd need a encodeUtf8 that can write directly to a pointer to solve that.

withText :: Text -> (CString -> IO a) -> IO a Source #

ForeignPtr

withForeignPtrs :: [ForeignPtr a] -> ([Ptr a] -> IO b) -> IO b Source #

FunPtr

makeFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a) Source #

Forgetting to call freeHaskellFunPtr is an easy way to leak memory. So all FunPtrs should be created with this function, and always bee freed with freeFunPtr. That way I can log creates and frees to ensure they are balanced. Use tools/track_funptr.py to automate that.