From: reid Date: Thu, 8 Aug 2002 22:29:28 +0000 (+0000) Subject: [project @ 2002-08-08 22:29:28 by reid] X-Git-Tag: nhc98-1-18-release~909 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=1777f7c6b99c6c57766a65f854d27cf86c140f52;p=ghc-base.git [project @ 2002-08-08 22:29:28 by reid] Hugs provides makeForeignPtr instead of newForeignPtr. It is hoped that these macros overcome the difference. + #ifdef __HUGS__ + #define MAKE_ARRAY(x) makeForeignPtr (x) free + #else + #define MAKE_ARRAY(x) newForeignPtr (x) (free (x)) + #endif I could probably get away with introducing a Haskell functions instead of a macro.. [Untested since Data.Array.Base requires the pattern guard extension so I can't load it. Still, I think this will be ready to go once we fix D.A.B] --- diff --git a/Data/Array/Storable.hs b/Data/Array/Storable.hs index 2ca8dde..afc36f8 100644 --- a/Data/Array/Storable.hs +++ b/Data/Array/Storable.hs @@ -49,6 +49,12 @@ import Data.Array.Base import Data.Array.MArray import Foreign hiding (newArray) +#ifdef __HUGS__ +#define MAKE_ARRAY(x) makeForeignPtr (x) free +#else +#define MAKE_ARRAY(x) newForeignPtr (x) (free (x)) +#endif + data StorableArray i e = StorableArray !i !i !(ForeignPtr e) instance HasBounds StorableArray where @@ -59,14 +65,14 @@ 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 <- MAKE_ARRAY(a) 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 <- MAKE_ARRAY(a) return (StorableArray l u fp) unsafeRead (StorableArray _ _ fp) i =