Safe Haskell | None |
---|---|
Language | Haskell98 |
This is a drop-in replacement for Foreign and Foreign.C. The
difference is that it uses a CStorable
class instead of
Storable
, and only C types are in CStorable. Otherwise, it's
easy to corrupt memory by accidentally marshalling a haskell type into a
C struct.
It tries to export all the same things that Foreign and Foreign.C do, but because I only copied the things I need, it's not complete.
- class CStorable a where
- alloca :: forall a b. CStorable a => (Ptr a -> IO b) -> IO b
- malloc :: CStorable a => IO (Ptr a)
- mallocArray :: CStorable a => Int -> IO (Ptr a)
- allocaArray :: CStorable a => Int -> (Ptr a -> IO b) -> IO b
- pokeArray :: CStorable a => Ptr a -> [a] -> IO ()
- peekArray :: CStorable a => Int -> Ptr a -> IO [a]
- newArray :: CStorable a => [a] -> IO (Ptr a)
- withArray :: CStorable a => [a] -> (Ptr a -> IO b) -> IO b
- withArrayLen :: CStorable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
- withArrayLenNull :: CStorable a => [a] -> (Int -> Ptr a -> IO b) -> IO b
- copyArray :: CStorable a => Ptr a -> Ptr a -> Int -> IO ()
- with :: CStorable a => a -> (Ptr a -> IO b) -> IO b
- module Data.Int
- module Data.Word
- module Foreign.C
- module Foreign.Ptr
- module Foreign.StablePtr
- module Foreign.ForeignPtr
- module Foreign.Marshal.Alloc
- module Foreign.Marshal.Utils
CStorable
class CStorable a where Source #
alignment :: a -> Int Source #
peekElemOff :: Ptr a -> Int -> IO a Source #
pokeElemOff :: Ptr a -> Int -> a -> IO () Source #
peekByteOff :: Ptr b -> Int -> IO a Source #
pokeByteOff :: Ptr b -> Int -> a -> IO () Source #
basic types
words
ints
ptrs
Foreign.Marshal.Alloc
Foreign.Marshal.Array
withArrayLenNull :: CStorable a => [a] -> (Int -> Ptr a -> IO b) -> IO b Source #
Like withArrayLen
, except if the list is null, then pass (0, nullPtr).
Foreign.Marshal.Utils
module Data.Int
module Data.Word
module Foreign.C
module Foreign.Ptr
module Foreign.StablePtr
module Foreign.ForeignPtr
module Foreign.Marshal.Alloc
module Foreign.Marshal.Utils