unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Chris Vine <vine35792468@gmail.com>
To: guile-user@gnu.org
Subject: Re: Calling back scheme from C
Date: Tue, 22 Sep 2020 10:50:26 +0100	[thread overview]
Message-ID: <20200922105026.5783d9ab0dd3641391cdd8c9@gmail.com> (raw)
In-Reply-To: <3a0ccd31a195f1544038b4ccc5ff1d15667a8e0d.camel@divoplade.fr>

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.



  reply	other threads:[~2020-09-22  9:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22  6:25 Calling back scheme from C divoplade
2020-09-22  9:50 ` Chris Vine [this message]
2020-09-22 10:36   ` divoplade
2020-09-22 14:47     ` Chris Vine
2020-09-22 15:48 ` divoplade

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200922105026.5783d9ab0dd3641391cdd8c9@gmail.com \
    --to=vine35792468@gmail.com \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).