X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FArray%2FStorable.hs;h=39abe70a23fa2fc06c81ab10092fe1e900e5fad7;hb=cf60c1b36b79bb79003825e4e1d7647a301a9c6e;hp=76d2dae38ed309cd656d5fc49875a246e7037ad8;hpb=1e2f2d4790e7070be1a507dc8182070d2205fb34;p=ghc-base.git diff --git a/Data/Array/Storable.hs b/Data/Array/Storable.hs index 76d2dae..39abe70 100644 --- a/Data/Array/Storable.hs +++ b/Data/Array/Storable.hs @@ -1,15 +1,13 @@ ----------------------------------------------------------------------------- --- +-- | -- Module : Data.Array.Storable -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org -- Stability : experimental -- Portability : non-portable -- --- $Id: Storable.hs,v 1.2 2001/07/04 10:51:09 simonmar Exp $ --- -- A storable array is an IO-mutable array which stores its -- contents in a contiguous memory block living in the C -- heap. Elements are stored according to the class Storable. @@ -59,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 =