(
ForeignPtr(..),
FinalizerPtr,
- newForeignPtr,
newForeignPtr_,
mallocForeignPtr,
mallocForeignPtrBytes,
import Control.Monad ( sequence_ )
import Foreign.Ptr
import Foreign.Storable
-import Data.Dynamic
+import Data.Typeable
import GHC.List ( null )
import GHC.Base
instance Show (ForeignPtr a) where
showsPrec p f = showsPrec p (unsafeForeignPtrToPtr f)
-#include "Dynamic.h"
+#include "Typeable.h"
INSTANCE_TYPEABLE1(ForeignPtr,foreignPtrTc,"ForeignPtr")
-- |A Finaliser is represented as a pointer to a foreign function that, at
--
type FinalizerPtr a = FunPtr (Ptr a -> IO ())
-newForeignPtr :: Ptr a -> FinalizerPtr a -> IO (ForeignPtr a)
--- ^Turns a plain memory reference into a foreign pointer, and
--- associates a finaliser with the reference. The finaliser will be executed
--- after the last reference to the foreign object is dropped. Note that there
--- is no guarantee on how soon the finaliser is executed after the last
--- reference was dropped; this depends on the details of the Haskell storage
--- manager. The only guarantee is that the finaliser runs before the program
--- terminates.
-newForeignPtr p finalizer
- = do fObj <- newForeignPtr_ p
- addForeignPtrFinalizer fObj finalizer
- return fObj
-
newConcForeignPtr :: Ptr a -> IO () -> IO (ForeignPtr a)
-- ^Turns a plain memory reference into a foreign object
-- by associating a finaliser - given by the monadic operation
(# s, MallocPtr mbarr# r #)
}
-addForeignPtrFinalizer :: ForeignPtr a -> FinalizerPtr a -> IO ()
+addForeignPtrFinalizer :: FinalizerPtr a -> ForeignPtr a -> IO ()
-- ^This function adds a finaliser to the given foreign object. The
-- finalizer will run /before/ all other finalizers for the same
-- object which have already been registered.
-addForeignPtrFinalizer fptr finalizer =
+addForeignPtrFinalizer finalizer fptr =
addForeignPtrConcFinalizer fptr
(mkFinalizer finalizer (unsafeForeignPtrToPtr fptr))