Comment 4 for bug 1587983

Revision history for this message
Douglas Katzman (dougk) wrote :

I'd like to propose a changed finalizer API.

A new subtype of weak pointer shall have one additional slot for the finalizer function (or list of functions if there is more than one for the same finalized object).

MAKE-WEAK-POINTER returns the familiar weak-pointer, but MAKE-FINALIZER would return this new kind of weak-pointer with the additional slot.
To cancel finalization is completely trivial: set the functions in the finalizer object to NIL.
RUN-PENDING-FINALIZERS can delete the finalizer that has no functions in it when it encounters it (after GC breaks the weak-pointer) just as it would for a finalizer that has functions to run. There's no difference there. Aside from the new object type, there's another low-level change: GC must build a list of finalizer actions for Lisp to run in post-gc. That's easy; it already has explicit knowledge of the weak-pointers that it smashed on any GC cycle.

Is there a drawback to this approach? Importantly, will consumers of this API end up having to build their own hash-table of object to finalizer? If so, this is not a huge win, though I still like the idea of handing the user a cookie.