Proposed change to ForeignPtr

George Russell ger at
Fri Aug 9 12:29:13 EDT 2002

Alastair wrote
> I propose the following changes:
> 1) Add these functions:
>   makeForeignPtr :: Ptr a -> FunPtr (Ptr a -> IO ()) -> IO ForeignObj
>   attachForeignPtrFinalizer :: ForeignPtr a -> FunPtr (Ptr a -> IO ()) -> IO ()
> 2) Remove newForeignPtr and addForeignPtrFinalizer
I don't understand this proposal.  What is a ForeignObj?

I call a C function, which gives me a cString :: Ptr CChar, and
it's my responsibility to free it when I've finished with it.  So I convert it
to a ForeignPtr:

   foreignPtr <- mkForeignPtr cString

and then always refer to the pointer via foreignPtr.  When foreignPtr is garbage collected
the space is freed.  So how do I do this with your proposal?

More information about the FFI mailing list