mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-28 14:00:31 +02:00
FFI: Hold a weak reference to the procedure passed to `procedure->pointer'.
* libguile/foreign.c (scm_procedure_to_pointer): Keep a weak reference to PROC. * test-suite/tests/foreign.test ("procedure->pointer")["procedure is retained"]: New test.
This commit is contained in:
parent
4855c63441
commit
59a0273338
2 changed files with 20 additions and 2 deletions
|
@ -272,6 +272,22 @@
|
|||
(proc* (pointer->procedure void pointer '())))
|
||||
(proc*)
|
||||
called?)
|
||||
(throw 'unresolved)))
|
||||
|
||||
(pass-if "procedure is retained"
|
||||
;; The lambda passed to `procedure->pointer' must remain live.
|
||||
(if (defined? 'procedure->pointer)
|
||||
(let* ((ptr (procedure->pointer int
|
||||
(lambda (x) (+ x 7))
|
||||
(list int)))
|
||||
(procs (unfold (cut >= <> 10000)
|
||||
(lambda (i)
|
||||
(pointer->procedure int ptr (list int)))
|
||||
1+
|
||||
0)))
|
||||
(gc) (gc) (gc)
|
||||
(every (cut = <> 9)
|
||||
(map (lambda (f) (f 2)) procs)))
|
||||
(throw 'unresolved))))
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue