unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#10668: FFI: ‘set-pointer-finalizer!’ overrides the previous finalizer
@ 2012-01-30 22:31 Ludovic Courtès
  2012-07-06 18:26 ` Andy Wingo
  0 siblings, 1 reply; 2+ messages in thread
From: Ludovic Courtès @ 2012-01-30 22:31 UTC (permalink / raw)
  To: 10668

Hi,

The ‘set-pointer-finalizer!’ procedure is harmful because it erases any
previously set finalizer.

Said finalizer could come from a guardian:

   (define ptr (make-pointer 123))
   (define g (make-guardian))
   (g ptr)
   (set-pointer-finalizer! ptr (dynamic-func "scm_is_pair" (dynamic-link)))
   (set! ptr #f)
   (gc)

   (g)          ;; Should return PTR.
   => #f

or from a weak hash table:

   (define ptr (make-pointer 123))
   (define t (make-weak-value-hash-table))
   (hashq-set! t ptr #t)
   (set-pointer-finalizer! ptr (dynamic-func "scm_is_pair" (dynamic-link)))
   (set! ptr #f)
   (gc)
   (gc)

   (hash-fold alist-cons '() t)
   => ((#<pointer 0x7b> . #t))   ;; Should be the empty list.


There are several ways to fix this:

  1. Deprecate ‘set-pointer-finalizer!’ in favor of guardians, with the
     problem that it would be up to the user to actually call the
     guardians.

  2. Implement ‘set-pointer-finalizer!’ in terms of guardians, with a
     gc-hook to automatically call the guardians and invoke any
     finalizers.

  3. Fix ‘set-pointer-finalizer!’ to honor the previously-set finalizer,
     if any.  This means (a) finding a way to keep previous-finalizer
     info around, and (b) duplicating part of the (hairy) code from
     guardians.c to honor the previous finalizer.

None of these solutions is really pleasant.

Thoughts?

Thanks,
Ludo’.





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#10668: FFI: ‘set-pointer-finalizer!’ overrides the previous finalizer
  2012-01-30 22:31 bug#10668: FFI: ‘set-pointer-finalizer!’ overrides the previous finalizer Ludovic Courtès
@ 2012-07-06 18:26 ` Andy Wingo
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Wingo @ 2012-07-06 18:26 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 10668-done

On Mon 30 Jan 2012 23:31, ludo@gnu.org (Ludovic Courtès) writes:

> The ‘set-pointer-finalizer!’ procedure is harmful because it erases any
> previously set finalizer.
>
> Said finalizer could come from a guardian:
>
>    (define ptr (make-pointer 123))
>    (define g (make-guardian))
>    (g ptr)
>    (set-pointer-finalizer! ptr (dynamic-func "scm_is_pair" (dynamic-link)))
>    (set! ptr #f)
>    (gc)
>
>    (g)          ;; Should return PTR.
>    => #f

This has worked since 75ba64d6797f5857cc9885eb753126119a8c8b68.

Andy
-- 
http://wingolog.org/





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-07-06 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-01-30 22:31 bug#10668: FFI: ‘set-pointer-finalizer!’ overrides the previous finalizer Ludovic Courtès
2012-07-06 18:26 ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).