[trivial-garbage-devel] Finalize with closure

Hans Höglund hans at hanshoglund.se
Sat Dec 8 22:57:50 UTC 2012


Hello,

I found myself wanting to reference the finalized object from a finalizer, so I added this wrapper around trivial-garbage:finalize, using a weak pointer to avoid permanently referencing the object from the finalizer closure.

(defun add-finalizer (x f)
  (setf p (make-weak-pointer x))
  (setf g (lambda ()
             (funcall f (weak-pointer-value p))))
  (finalize x g))

Would there be any problems with adding this function to the main library? I could probably provide a patch if requested.

Best regards,
Hans



More information about the trivial-garbage-devel mailing list