X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FArray%2FStorable.hs;h=39abe70a23fa2fc06c81ab10092fe1e900e5fad7;hb=833c0251f3de7eafbc42b4ce67360e84afd071f4;hp=2ca8dde5da7620af3487944248a01754de0efb91;hpb=f7a485978f04e84b086f1974b88887cc72d832d0;p=ghc-base.git diff --git a/Data/Array/Storable.hs b/Data/Array/Storable.hs index 2ca8dde..39abe70 100644 --- a/Data/Array/Storable.hs +++ b/Data/Array/Storable.hs @@ -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 =