Actually in the current implementation the finalizers are not attached to the ForeignPtr at all: it's the other way around.
Ah, I see.
Fortunately, I don't think my sketched implementation depended on such an attachment since it added an attachment of its own. The design is intended to sit on top of the current GHC implementation (i.e., one with Haskell finalizers and no control over the order they are run).
Yes, you're right. We could do it that way. I'm also concerned about adding the extra overhead though, especially if this is something that will rarely be needed. Are we sure this is what we want? At least I can optimise mallocForeignPtr again and avoid registering the finalizer until the first call to addForeignPtrFinalizer. Cheers, Simon
On Thu, Sep 26, 2002 at 09:56:20AM +0100, Simon Marlow wrote:
Yes, you're right. We could do it that way. I'm also concerned about adding the extra overhead though, especially if this is something that will rarely be needed. Are we sure this is what we want?
It would - make addForeignPtrFinalizer usable - reduce the need to write finalizers in the foreign language - support the style where you do something and add the finalizer to undo it in the same place. but it's not absolutely essential, if (1) it's guaranteed that any additional finalizers run before storage from mallocForeignPtr is freed, and (2) there's a C interface hs_free() to free. Then you could always collect the finalizers in a single foreign language finalizer that calls them in the right order.
Did we ever sort out the original subject of this thread which was: Should finalizers on a given foreign pointer be executed in the order they were added? It is obvious what addForeignPtrFinalizer can be used for if this guarantee is made. As far as I can recall, no-one has suggested what addForeignPtrFinalizer is good for if this guarantee is _not_ made. Hugs makes this guarantee. I believe NHC can easily make this guarantee if they don't do so already. GHC does not make this guarantee but they know how to implement it. The current ffi spec (release candidate 7) does not make this guarantee. -- Alastair Reid alastair@reid-consulting-uk.ltd.uk Reid Consulting (UK) Limited http://www.reid-consulting-uk.ltd.uk/alastair/
On Tue, Nov 26, 2002 at 01:14:14PM +0000, Alastair Reid wrote:
Did we ever sort out the original subject of this thread which was:
Should finalizers on a given foreign pointer be executed in the order they were added?
I think that should be the reverse order. For example, if you add a finalizer to the result of mallocForeignPtr, you want it to run before the thing is freed. (That's what Hugs does now.)
participants (3)
-
Alastair Reid -
Ross Paterson -
Simon Marlow