-----------------------------------------------------------------------------
-- |
-- Module : Foreign.Storable
-----------------------------------------------------------------------------
-- |
-- Module : Foreign.Storable
- ( Storable(
- sizeOf, -- :: a -> Int
- alignment, -- :: a -> Int
- peekElemOff, -- :: Ptr a -> Int -> IO a
- pokeElemOff, -- :: Ptr a -> Int -> a -> IO ()
- peekByteOff, -- :: Ptr b -> Int -> IO a
- pokeByteOff, -- :: Ptr b -> Int -> a -> IO ()
- peek, -- :: Ptr a -> IO a
- poke) -- :: Ptr a -> a -> IO ()
+ ( Storable(
+ sizeOf, -- :: a -> Int
+ alignment, -- :: a -> Int
+ peekElemOff, -- :: Ptr a -> Int -> IO a
+ pokeElemOff, -- :: Ptr a -> Int -> a -> IO ()
+ peekByteOff, -- :: Ptr b -> Int -> IO a
+ pokeByteOff, -- :: Ptr b -> Int -> a -> IO ()
+ peek, -- :: Ptr a -> IO a
+ poke) -- :: Ptr a -> a -> IO ()
,Int8,Int16,Int32,Int64,Word8,Word16,Word32,Word64)
#else
,Int8,Int16,Int32,Int64,Word8,Word16,Word32,Word64)
#else
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
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
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',
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',
peekElemOff p i = liftM (/= (0::HTYPE_INT)) $ peekElemOff (castPtr p) i
pokeElemOff p i x = pokeElemOff (castPtr p) i (if x then 1 else 0::HTYPE_INT)
peekElemOff p i = liftM (/= (0::HTYPE_INT)) $ peekElemOff (castPtr p) i
pokeElemOff p i x = pokeElemOff (castPtr p) i (if x then 1 else 0::HTYPE_INT)
-#define STORABLE(T,size,align,read,write) \
-instance Storable (T) where { \
- sizeOf _ = size; \
- alignment _ = align; \
- peekElemOff = read; \
+#define STORABLE(T,size,align,read,write) \
+instance Storable (T) where { \
+ sizeOf _ = size; \
+ alignment _ = align; \
+ peekElemOff = read; \
pokeElemOff = write }
#ifdef __GLASGOW_HASKELL__
STORABLE(Char,SIZEOF_INT32,ALIGNMENT_INT32,
pokeElemOff = write }
#ifdef __GLASGOW_HASKELL__
STORABLE(Char,SIZEOF_INT32,ALIGNMENT_INT32,
#elif defined(__HUGS__)
STORABLE(Char,SIZEOF_HSCHAR,ALIGNMENT_HSCHAR,
#elif defined(__HUGS__)
STORABLE(Char,SIZEOF_HSCHAR,ALIGNMENT_HSCHAR,
#endif
STORABLE(Int,SIZEOF_HSINT,ALIGNMENT_HSINT,
#endif
STORABLE(Int,SIZEOF_HSINT,ALIGNMENT_HSINT,
STORABLE(Word,SIZEOF_HSWORD,ALIGNMENT_HSWORD,
STORABLE(Word,SIZEOF_HSWORD,ALIGNMENT_HSWORD,
#endif
STORABLE((Ptr a),SIZEOF_HSPTR,ALIGNMENT_HSPTR,
#endif
STORABLE((Ptr a),SIZEOF_HSPTR,ALIGNMENT_HSPTR,
STORABLE((FunPtr a),SIZEOF_HSFUNPTR,ALIGNMENT_HSFUNPTR,
STORABLE((FunPtr a),SIZEOF_HSFUNPTR,ALIGNMENT_HSFUNPTR,
STORABLE((StablePtr a),SIZEOF_HSSTABLEPTR,ALIGNMENT_HSSTABLEPTR,
STORABLE((StablePtr a),SIZEOF_HSSTABLEPTR,ALIGNMENT_HSSTABLEPTR,
STORABLE(Float,SIZEOF_HSFLOAT,ALIGNMENT_HSFLOAT,
STORABLE(Float,SIZEOF_HSFLOAT,ALIGNMENT_HSFLOAT,
STORABLE(Double,SIZEOF_HSDOUBLE,ALIGNMENT_HSDOUBLE,
STORABLE(Double,SIZEOF_HSDOUBLE,ALIGNMENT_HSDOUBLE,
STORABLE(Word8,SIZEOF_WORD8,ALIGNMENT_WORD8,
STORABLE(Word8,SIZEOF_WORD8,ALIGNMENT_WORD8,
STORABLE(Word16,SIZEOF_WORD16,ALIGNMENT_WORD16,
STORABLE(Word16,SIZEOF_WORD16,ALIGNMENT_WORD16,
STORABLE(Word32,SIZEOF_WORD32,ALIGNMENT_WORD32,
STORABLE(Word32,SIZEOF_WORD32,ALIGNMENT_WORD32,
STORABLE(Word64,SIZEOF_WORD64,ALIGNMENT_WORD64,
STORABLE(Word64,SIZEOF_WORD64,ALIGNMENT_WORD64,
STORABLE(Int8,SIZEOF_INT8,ALIGNMENT_INT8,
STORABLE(Int8,SIZEOF_INT8,ALIGNMENT_INT8,
STORABLE(Int16,SIZEOF_INT16,ALIGNMENT_INT16,
STORABLE(Int16,SIZEOF_INT16,ALIGNMENT_INT16,
STORABLE(Int32,SIZEOF_INT32,ALIGNMENT_INT32,
STORABLE(Int32,SIZEOF_INT32,ALIGNMENT_INT32,
STORABLE(Int64,SIZEOF_INT64,ALIGNMENT_INT64,
STORABLE(Int64,SIZEOF_INT64,ALIGNMENT_INT64,