Karya, built on 2022-03-21T01:30:44 (patch 89d1651424c35e564138d93424a157ff87457245)
Safe HaskellSafe-Inferred



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.

newCString0 :: 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.

newCStringNull0 :: Text -> IO CString Source #

Like newCString0, but optimize "" to nullptr. The C++ side has to be prepared for this.

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.

new :: CStorable a => a -> IO (Ptr a) Source #

This should be in c-storable, but updating via hackage is such a pain I'll inline it for now.