-{-# OPTIONS -fno-implicit-prelude #-}
+{-# OPTIONS_GHC -fno-implicit-prelude #-}
-----------------------------------------------------------------------------
-- |
-- Module : GHC.ForeignPtr
--
-----------------------------------------------------------------------------
+-- #hide
module GHC.ForeignPtr
(
ForeignPtr(..),
import Control.Monad ( sequence_ )
import Foreign.Ptr
import Foreign.Storable
-import Data.Typeable
import GHC.List ( null )
import GHC.Base
instance Show (ForeignPtr a) where
showsPrec p f = showsPrec p (unsafeForeignPtrToPtr f)
-#include "Typeable.h"
-INSTANCE_TYPEABLE1(ForeignPtr,foreignPtrTc,"ForeignPtr")
-
-- |A Finalizer is represented as a pointer to a foreign function that, at
-- finalisation time, gets as an argument a plain pointer variant of the
-- foreign pointer that the finalizer is associated with.
-- assume that the memory returned by 'mallocForeignPtr' has been
-- allocated with 'Foreign.Marshal.Alloc.malloc'.
mallocForeignPtr = doMalloc undefined
- where doMalloc :: Storable a => a -> IO (ForeignPtr a)
+ where doMalloc :: Storable b => b -> IO (ForeignPtr b)
doMalloc a = do
r <- newIORef []
IO $ \s ->
-- parameterised by one type into another type.
castForeignPtr f = unsafeCoerce# f
--- | Causes a the finalizers associated with a foreign pointer to be run
+-- | Causes the finalizers associated with a foreign pointer to be run
-- immediately.
finalizeForeignPtr :: ForeignPtr a -> IO ()
finalizeForeignPtr foreignPtr = do