[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling back scheme from C
From: |
Chris Vine |
Subject: |
Re: Calling back scheme from C |
Date: |
Tue, 22 Sep 2020 10:50:26 +0100 |
On Tue, 22 Sep 2020 08:25:25 +0200
divoplade <d@divoplade.fr> wrote:
> Hello guile,
>
> I am having a hard time understanding what I do wrong when trying to
> pass a guile function as a C callback (from C).
>
> You should be able to trigger the bug by saving the 3 attached files
> and running:
>
> guix build -L . pkg-with-the-bug
>
> The bug disappears when ignoring the scheme callback, so I suspect it
> has something to do with the callback and not further functions:
>
> guix build -L . pkg-without-the-bug
>
> Does anyone see an error?
I haven't looked at your code but note that GC'ed objects held only in
the C or C++ heap (say as closures of a C function) are not visible to
the GC and need protection with scm_gc_protect_object, otherwise they
can be collected while still in use by C code. If you have one-shot C
callbacks taking guile objects as closures which are stored as
pointers in the C heap, you can call scm_gc_unprotect_object as the last
thing the callback does in order to get the object collected
subsequently.
This may not be your issue. I offer it as something I had to deal with
in code of my own to prevent incorrect collection for closures of
callbacks executed by a C event loop.