Karya, built on 2018-02-23T20:23:55 (patch cf8565b7ac832266878af99a942555d139065f12)

Safe HaskellNone




Utilities for C wrappers.

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



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 #


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


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.