[project @ 2003-08-22 08:58:30 by panne]
[ghc-base.git] / Data / Array / Storable.hs
index 2ca8dde..39abe70 100644 (file)
@@ -57,16 +57,15 @@ instance HasBounds StorableArray where
 instance Storable e => MArray StorableArray e IO where
 
     newArray (l,u) init = do
-        a <- mallocArray size
-        sequence_ [pokeElemOff a i init | i <- [0..size-1]]
-        fp <- newForeignPtr a (free a)
+        fp <- mallocForeignPtrArray size
+        withForeignPtr fp $ \a ->
+            sequence_ [pokeElemOff a i init | i <- [0..size-1]]
         return (StorableArray l u fp)
         where
         size = rangeSize (l,u)
 
     newArray_ (l,u) = do
-        a  <- mallocArray (rangeSize (l,u))
-        fp <- newForeignPtr a (free a)
+        fp <- mallocForeignPtrArray (rangeSize (l,u))
         return (StorableArray l u fp)
 
     unsafeRead (StorableArray _ _ fp) i =