X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Foreign%2FMarshal%2FArray.hs;h=9e8d08287da8174200729c7218dff9936277696b;hb=98daa4a448e019083d52ccec219a912021a0bfb0;hp=8e013fe859677cdbf27ff9b0903483bff775bfb4;hpb=0fcdf0d718105c74453a41620c6242ac23897ad7;p=ghc-base.git diff --git a/Foreign/Marshal/Array.hs b/Foreign/Marshal/Array.hs index 8e013fe..9e8d082 100644 --- a/Foreign/Marshal/Array.hs +++ b/Foreign/Marshal/Array.hs @@ -63,8 +63,8 @@ module Foreign.Marshal.Array ( ) where import Foreign.Ptr (Ptr, plusPtr) -import Foreign.Storable (Storable(sizeOf,peekElemOff,pokeElemOff)) -import Foreign.Marshal.Alloc (mallocBytes, allocaBytes, reallocBytes) +import Foreign.Storable (Storable(alignment,sizeOf,peekElemOff,pokeElemOff)) +import Foreign.Marshal.Alloc (mallocBytes, allocaBytesAligned, reallocBytes) import Foreign.Marshal.Utils (copyBytes, moveBytes) #ifdef __GLASGOW_HASKELL__ @@ -101,7 +101,8 @@ allocaArray :: Storable a => Int -> (Ptr a -> IO b) -> IO b allocaArray = doAlloca undefined where doAlloca :: Storable a' => a' -> Int -> (Ptr a' -> IO b') -> IO b' - doAlloca dummy size = allocaBytes (size * sizeOf dummy) + doAlloca dummy size = allocaBytesAligned (size * sizeOf dummy) + (alignment dummy) -- |Like 'allocaArray', but add an extra position to hold a special -- termination element. @@ -129,10 +130,8 @@ reallocArray0 ptr size = reallocArray ptr (size + 1) -- marshalling -- ----------- --- |Convert an array of given length into a Haskell list. This version --- traverses the array backwards using an accumulating parameter, --- which uses constant stack space. The previous version using mapM --- needed linear stack space. +-- |Convert an array of given length into a Haskell list. The implementation +-- is tail-recursive and so uses constant stack space. -- peekArray :: Storable a => Int -> Ptr a -> IO [a] peekArray size ptr | size <= 0 = return []