Safe Haskell | None |
---|---|
Language | Haskell2010 |
- module Control.Applicative
- module Data.Word
- module Foreign.C
- module System.Mesos.Types
- runManaged :: Managed () -> IO ()
- data Managed a :: * -> *
- class CPPValue a where
- data ByteString :: *
- data Ptr a :: * -> *
- data FunPtr a :: * -> *
- nullPtr :: Ptr a
- alloc :: Storable a => Managed (Ptr a)
- allocMaybe :: Storable a => Maybe a -> Managed (Ptr a)
- arrayPair :: Storable a => Managed (Ptr a, Ptr CInt)
- peek :: Storable a => Ptr a -> Managed a
- poke :: Storable a => Ptr a -> a -> Managed ()
- pokeMaybe :: Storable a => Ptr a -> Maybe a -> Managed ()
- arrayLen :: Storable a => [a] -> Managed (Ptr a, Int)
- cstring :: ByteString -> Managed (Ptr CChar, Int)
- maybeCString :: Maybe ByteString -> Managed (Ptr CChar, Int)
- peekArray :: (Ptr (Ptr a), Ptr CInt) -> Managed [Ptr a]
- peekArray' :: (Ptr (Ptr a), Int) -> Managed [Ptr a]
- peekCString :: (Ptr (Ptr CChar), Ptr CInt) -> Managed ByteString
- peekCString' :: (Ptr (Ptr CChar), CInt) -> Managed ByteString
- peekMaybeCString :: (Ptr (Ptr CChar), Ptr CInt) -> Managed (Maybe ByteString)
- cppValue :: CPPValue a => a -> Managed (Ptr a)
- peekCPP :: CPPValue a => Ptr a -> Managed a
- peekMaybeCPP :: CPPValue a => Ptr (Ptr a) -> Managed (Maybe a)
- type CBool = CUChar
- toCBool :: Bool -> CBool
- fromCBool :: CBool -> Bool
- toStatus :: CInt -> Status
- peekMaybe :: Storable a => Ptr (Ptr a) -> Managed (Maybe a)
- peekMaybeBS :: Ptr (Ptr CChar) -> Ptr CInt -> Managed (Maybe ByteString)
- peekMaybePrim :: Storable a => Ptr a -> Ptr CBool -> Managed (Maybe a)
- class Storable a
- liftIO :: MonadIO m => forall a. IO a -> m a
- type ToID a = Ptr CChar -> CInt -> IO a
- type FromID a = a -> Ptr (Ptr CChar) -> IO CInt
- defEq :: Eq a => a -> Maybe a -> Maybe a -> Bool
- makePrefixFields :: [Char] -> Name -> DecsQ
Documentation
module Control.Applicative
module Data.Word
module Foreign.C
module System.Mesos.Types
runManaged :: Managed () -> IO ()
Run a Managed
computation, enforcing that no acquired resources leak
marshal :: a -> Managed (Ptr a) Source
unmarshal :: Ptr a -> Managed a Source
destroy :: Ptr a -> IO () Source
equalExceptDefaults :: Eq a => a -> a -> Bool Source
data ByteString :: *
A space-efficient representation of a Word8
vector, supporting many
efficient operations.
A ByteString
contains 8-bit bytes, or by using the operations from
Data.ByteString.Char8 it can be interpreted as containing 8-bit
characters.
data Ptr a :: * -> *
A value of type
represents a pointer to an object, or an
array of objects, which may be marshalled to or from Haskell values
of type Ptr
aa
.
The type a
will often be an instance of class
Storable
which provides the marshalling operations.
However this is not essential, and you can provide your own operations
to access the pointer. For example you might write small foreign
functions to get or set the fields of a C struct
.
data FunPtr a :: * -> *
A value of type
is a pointer to a function callable
from foreign code. The type FunPtr
aa
will normally be a foreign type,
a function type with zero or more arguments where
- the argument types are marshallable foreign types,
i.e.
Char
,Int
,Double
,Float
,Bool
,Int8
,Int16
,Int32
,Int64
,Word8
,Word16
,Word32
,Word64
,
,Ptr
a
,FunPtr
a
or a renaming of any of these usingStablePtr
anewtype
. - the return type is either a marshallable foreign type or has the form
whereIO
tt
is a marshallable foreign type or()
.
A value of type
may be a pointer to a foreign function,
either returned by another foreign function or imported with a
a static address import likeFunPtr
a
foreign import ccall "stdlib.h &free" p_free :: FunPtr (Ptr a -> IO ())
or a pointer to a Haskell function created using a wrapper stub
declared to produce a FunPtr
of the correct type. For example:
type Compare = Int -> Int -> Bool foreign import ccall "wrapper" mkCompare :: Compare -> IO (FunPtr Compare)
Calls to wrapper stubs like mkCompare
allocate storage, which
should be released with freeHaskellFunPtr
when no
longer required.
To convert FunPtr
values to corresponding Haskell functions, one
can define a dynamic stub for the specific foreign type, e.g.
type IntFunction = CInt -> IO () foreign import ccall "dynamic" mkFun :: FunPtr IntFunction -> IntFunction
maybeCString :: Maybe ByteString -> Managed (Ptr CChar, Int) Source
peekCString :: (Ptr (Ptr CChar), Ptr CInt) -> Managed ByteString Source
peekCString' :: (Ptr (Ptr CChar), CInt) -> Managed ByteString Source
peekMaybeCString :: (Ptr (Ptr CChar), Ptr CInt) -> Managed (Maybe ByteString) Source
peekMaybeBS :: Ptr (Ptr CChar) -> Ptr CInt -> Managed (Maybe ByteString) Source
class Storable a
The member functions of this class facilitate writing values of primitive types to raw memory (which may have been allocated with the above mentioned routines) and reading values from blocks of raw memory. The class, furthermore, includes support for computing the storage requirements and alignment restrictions of storable types.
Memory addresses are represented as values of type
, for some
Ptr
aa
which is an instance of class Storable
. The type argument to
Ptr
helps provide some valuable type safety in FFI code (you can't
mix pointers of different types without an explicit cast), while
helping the Haskell type system figure out which marshalling method is
needed for a given pointer.
All marshalling between Haskell and a foreign language ultimately
boils down to translating Haskell data structures into the binary
representation of a corresponding data structure of the foreign
language and vice versa. To code this marshalling in Haskell, it is
necessary to manipulate primitive data types stored in unstructured
memory blocks. The class Storable
facilitates this manipulation on
all types for which it is instantiated, which are the standard basic
types of Haskell, the fixed size Int
types (Int8
, Int16
,
Int32
, Int64
), the fixed size Word
types (Word8
, Word16
,
Word32
, Word64
), StablePtr
, all types from Foreign.C.Types,
as well as Ptr
.
Minimal complete definition: sizeOf
, alignment
, one of peek
,
peekElemOff
and peekByteOff
, and one of poke
, pokeElemOff
and
pokeByteOff
.
sizeOf, alignment, (peek | peekElemOff | peekByteOff), (poke | pokeElemOff | pokeByteOff)
makePrefixFields :: [Char] -> Name -> DecsQ Source