bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#26503: Local variables reclaimed early vs. finalizers


From: Ludovic Courtès
Subject: bug#26503: Local variables reclaimed early vs. finalizers
Date: Fri, 14 Apr 2017 23:56:50 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Hello!

Consider this code:

--8<---------------cut here---------------start------------->8---
(use-modules (system foreign))

(define %table
  (make-weak-value-hash-table))

(define %abort
  (dynamic-func "abort" (dynamic-link)))

(let ((ptr (make-pointer 123 %abort)))
  (display "hello\n")
  (gc))
--8<---------------cut here---------------end--------------->8---

Guile is free to collect ‘ptr’ when ‘gc’ is called since it has become
unreachable at that point; that’s what 2.2.0 does, as explained in
‘NEWS’.

However, there’s a finalizer here so collecting ‘ptr’ has an observable
side effect.  This side effect makes the semantic change visible: the
“expected” semantics would be that ‘ptr’ is not subject to GC while it’s
in scope.

(In 2.0 the finalizer is not called until ‘ptr’ is no longer in scope.)

I’m not sure this counts as a bug, but it’s certainly a pitfall when
working with finalizers and the FFI.

Thoughts?

Ludo’.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]