From 42d83e2ac9599ac97e33c0a93623111e095e737d Mon Sep 17 00:00:00 2001 From: ross Date: Thu, 12 Jun 2003 12:55:28 +0000 Subject: [PATCH] [project @ 2003-06-12 12:55:27 by ross] move portable newForeignPtr from GHC.ForeignPtr to Foreign.ForeignPtr --- Foreign/ForeignPtr.hs | 18 +++++++++++++----- GHC/ForeignPtr.hs | 14 -------------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Foreign/ForeignPtr.hs b/Foreign/ForeignPtr.hs index 9d7ebf0..a545396 100644 --- a/Foreign/ForeignPtr.hs +++ b/Foreign/ForeignPtr.hs @@ -88,6 +88,19 @@ instance Show (ForeignPtr a) where #ifndef __NHC__ +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 + withForeignPtr :: ForeignPtr a -> (Ptr a -> IO b) -> IO b -- ^This is a way to look at the pointer living inside a -- foreign object. This function takes a function which is @@ -114,11 +127,6 @@ withForeignPtr fo io return r #endif /* ! __NHC__ */ -#ifdef __HUGS__ --- temporary aliasing until hugs catches up -unsafeForeignPtrToPtr = foreignPtrToPtr -#endif - #ifndef __GLASGOW_HASKELL__ mallocForeignPtr :: Storable a => IO (ForeignPtr a) mallocForeignPtr = do diff --git a/GHC/ForeignPtr.hs b/GHC/ForeignPtr.hs index 07c201a..2112b34 100644 --- a/GHC/ForeignPtr.hs +++ b/GHC/ForeignPtr.hs @@ -17,7 +17,6 @@ module GHC.ForeignPtr ( ForeignPtr(..), FinalizerPtr, - newForeignPtr, newForeignPtr_, mallocForeignPtr, mallocForeignPtrBytes, @@ -79,19 +78,6 @@ INSTANCE_TYPEABLE1(ForeignPtr,foreignPtrTc,"ForeignPtr") -- 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 -- 1.7.10.4