From: ross Date: Tue, 4 Nov 2003 21:59:23 +0000 (+0000) Subject: [project @ 2003-11-04 21:59:23 by ross] X-Git-Tag: nhc98-1-18-release~454 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=d04a1ce782bbc6023dcdf4e02626aad036a32017;p=ghc-base.git [project @ 2003-11-04 21:59:23 by ross] Hugs only: add finalizers with environments, as per the latest FFI draft. --- diff --git a/Foreign/ForeignPtr.hs b/Foreign/ForeignPtr.hs index 9705181..8f8f64b 100644 --- a/Foreign/ForeignPtr.hs +++ b/Foreign/ForeignPtr.hs @@ -20,9 +20,16 @@ module Foreign.ForeignPtr -- * Finalised data pointers ForeignPtr , FinalizerPtr +#ifdef __HUGS__ + , FinalizerEnvPtr +#endif , newForeignPtr , newForeignPtr_ , addForeignPtrFinalizer +#ifdef __HUGS__ + , newForeignPtrEnv + , addForeignPtrFinalizerEnv +#endif , withForeignPtr , unsafeForeignPtrToPtr , touchForeignPtr @@ -127,6 +134,19 @@ withForeignPtr fo io return r #endif /* ! __NHC__ */ +#ifdef __HUGS__ +-- | This variant of 'newForeignPtr' adds a finalizer that expects an +-- environment in addition to the finalized pointer. The environment +-- that will be passed to the finalizer is fixed by the second argument to +-- 'newForeignPtrEnv'. +newForeignPtrEnv :: + FinalizerEnvPtr env a -> Ptr env -> Ptr a -> IO (ForeignPtr a) +newForeignPtrEnv finalizer env p + = do fObj <- newForeignPtr_ p + addForeignPtrFinalizerEnv finalizer env fObj + return fObj +#endif /* __HUGS__ */ + #ifndef __GLASGOW_HASKELL__ mallocForeignPtr :: Storable a => IO (ForeignPtr a) mallocForeignPtr = do