unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* C calling Scheme and garbage collection
@ 2019-06-27 16:38 Isaac Jurado
  2019-06-27 19:52 ` Greg Troxel
  2019-07-01  1:26 ` Mark H Weaver
  0 siblings, 2 replies; 8+ messages in thread
From: Isaac Jurado @ 2019-06-27 16:38 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

Hello,

I'm playing with event loop libraries implemented in C (libev, libevent,
etc... in my case libsystemd), but configuring them from Guile.

The qsort example in the documentation [1] seems safe because the qsort C
function directly calls back, so the callback Scheme bindings stay
referenced (by the Scheme code calling qsort) during all the C code
execution.

Now, in C event loops the situation is different.  There is one call to
configure the event callback, in which the function and data pointers are
lent to the loop; and then there is the main loop or the single iteration
call.

The way I see it, suppose I add a timer.  I call one C function passing a
(proceudre->pointer) and an (scm->pointer).  In a future time, those
pointers will be used by the C event loop.  If a garbage collection happens
in the middle, the results of (procedure->pointer) and (scm->pointer) may
have been reclaimed by the time the C event loop calls back.

However, I've tried forcing (gc) between the two steps mentioned and it
looks to be working fine.  I have also reviewed some of the code [2][3] and
some additional weak references seem to be created.

I'll try a couple of combinations to see if I can "break" it, in order to
learn the limitations of C calling Scheme within Guile.  But if someone in
the list has experienced with this already, I would very glad to read some
advice about it.

Best regards.

References:

[1]
https://www.gnu.org/software/guile/manual/html_node/Dynamic-FFI.html#index-procedure_002d_003epointer
[2]
http://git.savannah.gnu.org/cgit/guile.git/tree/libguile/foreign.c?h=stable-2.2#n185
[3]
http://git.savannah.gnu.org/cgit/guile.git/tree/libguile/foreign.c?h=stable-2.2#n1080

-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding"
Leonardo da Vinci

[-- Attachment #2: Type: text/html, Size: 2523 bytes --]

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

end of thread, other threads:[~2019-07-01  1:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-06-27 16:38 C calling Scheme and garbage collection Isaac Jurado
2019-06-27 19:52 ` Greg Troxel
2019-06-28 11:07   ` Isaac Jurado
2019-06-29 17:44     ` Greg Troxel
2019-06-30 12:17       ` David Pirotte
2019-06-30 20:05       ` Isaac Jurado
2019-06-30 12:51   ` Hans Åberg
2019-07-01  1:26 ` Mark H Weaver

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).