addForeignPtrFinalizer

Ross Paterson ross at soi.city.ac.uk
Tue Sep 24 13:27:11 EDT 2002


On Tue, Sep 24, 2002 at 06:07:12PM +0100, Alastair Reid wrote:
> Seems like it'd be reasonable to specify an order for these.
> 
> An alternative would be to drop addForeignPtrFinalizer.  I have no
> idea what the motivation for this function is since I can't think when
> you'd need/want/prefer to add finalization actions incrementally
> instead of doing it in one step.  Can someone give a motivating
> example where there is some advantage in adding finalization actions
> incrementally?

Consider regcomp in Test.Regex.Posix.  You malloc an array of bytes and
make that a ForeignPtr by adding finalizerFree (your ptr_free).  Then you
pass it to the C regcomp() function.  Now you want to add the C regfree()
function as a finalizer.  You could call both from a single C finalizer
(as Manuel suggests in another thread) but I prefer Haskell.  Also that
option doesn't work if the array was allocated with mallocForeignPtrBytes.



More information about the FFI mailing list