import Control.Monad
import Foreign.Ptr (Ptr, plusPtr)
import Foreign.Storable (Storable(sizeOf,peekElemOff,pokeElemOff))
-import Foreign.Marshal.Alloc (alloca, mallocBytes, allocaBytes, reallocBytes)
+import Foreign.Marshal.Alloc (mallocBytes, allocaBytes, reallocBytes)
import Foreign.Marshal.Utils (copyBytes, moveBytes)
#ifdef __GLASGOW_HASKELL__
-- |Convert an array terminated by the given end marker into a Haskell list
--
peekArray0 :: (Storable a, Eq a) => a -> Ptr a -> IO [a]
-peekArray0 marker ptr = loop 0
- where
- loop i = do
- val <- peekElemOff ptr i
- if val == marker then return [] else do
- rest <- loop (i+1)
- return (val:rest)
+peekArray0 marker ptr = do
+ size <- lengthArray0 marker ptr
+ peekArray size ptr
-- |Write the list elements consecutive into memory
--
pokeArray :: Storable a => Ptr a -> [a] -> IO ()
#ifndef __GLASGOW_HASKELL__
-pokeArray ptrs vals = zipWithM_ (pokeElemOff ptr) [0..] vals
+pokeArray ptr vals = zipWithM_ (pokeElemOff ptr) [0..] vals
#else
pokeArray ptr vals = go vals 0#
where go [] n# = return ()