Ross Paterson ross at
Wed Sep 25 06:23:39 EDT 2002

On Wed, Sep 25, 2002 at 10:25:31AM +0100, Simon Marlow wrote:
> > If the struct was allocated with mallocForeignPtr,
> > you're stuck.  You've no choice but to use addForeignPtrFinalizer,
> > except that you can't because the order of finalizers is unspecified.
> I can guarantee in GHC that if you add a finalizer to a ForeignPtr made
> with mallocForeignPtr, then it will run before the memory is released.

Clunky, but if the spec said that it might be just enough.  Hugs and
Nhc could implement it by running the finalizers in the reverse order.
(Neither of them implement addForeignPtrFinalizer yet, but they both
store the finalizer in a ForeignPtr structure, and could store a list
of finalizers instead.)

> I tell you what, I'll implement finalizer ordering if you guys implement
> full Haskell finalizers :-)

How about providing newForeignPtr as specified?  (Or are you still hoping?)

More information about the FFI mailing list