Safe Haskell | Safe-Inferred |
---|
Utilities for C wrappers.
- Functions to convert between haskell and c types.
- Generic UI debugging functions.
Synopsis
- c_int :: Int -> CInt
- c_nat :: Int -> CInt
- c_uchar :: Integral a => a -> CUChar
- c_char :: Char -> CChar
- c_rune :: Char -> Word.Word32
- c_double :: Double -> CDouble
- c_float :: Float -> CFloat
- hs_double :: CDouble -> Double
- c_bool :: Bool -> CChar
- bytesToCString0 :: ByteString.ByteString -> IO CString
- newCString0 :: Text -> IO CString
- newCStringNull0 :: Text -> IO CString
- peekCString :: CString -> IO Text
- withText :: Text -> (CString -> IO a) -> IO a
- decodeUtf8 :: ByteString.ByteString -> Text
- withForeignPtrs :: [ForeignPtr a] -> ([Ptr a] -> IO b) -> IO b
- makeFunPtr :: String -> IO (FunPtr a) -> IO (FunPtr a)
- freeFunPtr :: FunPtr a -> IO ()
- new :: CStorable a => a -> IO (Ptr a)
convert
c_rune :: Char -> Word.Word32 Source #
This corresponds to utf8::rune.
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.
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.
freeFunPtr :: FunPtr a -> IO () Source #