Karya, built on 2018-05-31T02:46:59 (patch 0a1a35479c514820d77330ae8a978975ba22a47a)

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.