From: David Pirotte <david@altosw.be>
To: Greg Troxel <gdt@lexort.com>
Cc: Isaac Jurado <diptongo@gmail.com>, guile-devel@gnu.org
Subject: Re: C calling Scheme and garbage collection
Date: Sun, 30 Jun 2019 09:17:32 -0300 [thread overview]
Message-ID: <20190630091732.0a6540ef@capac> (raw)
In-Reply-To: <rmiblygmgm6.fsf@s1.lexort.com>
[-- Attachment #1: Type: text/plain, Size: 1423 bytes --]
Hello,
>...
> In my experience, it's definitely not ok to capture a pointer to a
> scheme object and store it for later use without protecting the scheme
> object from gc by holding a reference.
I recently had a similar conversation, here is one of the emails of the thread, the
one that lists a series of examples, and out of those, only the last example works:
https://lists.gnu.org/archive/html/guile-devel/2019-03/msg00013.html
In that last example, I am holding a reference to both the data and their pointer,
but it seemed to me, after further local tests, that it is sufficient to hold on a
reference to the pointers, not the pointers and the data:
scheme@(guile-user)> ,use (system foreign)
scheme@(guile-user)> (define ptr-1 (string->pointer "Hello"))
scheme@(guile-user)> (define ptr-2 (string->pointer "there!"))
scheme@(guile-user)> (make-c-struct (list '* '*) (list ptr-1 ptr-2))
$2 = #<pointer 0x5623b599a350>
scheme@(guile-user)> (parse-c-struct $2 (list '* '*))
$3 = (#<pointer 0x5623b51b1110> #<pointer 0x5623b591e6f0>)
scheme@(guile-user)> (map pointer->string $3)
$4 = ("Hello" "there!")
scheme@(guile-user)> (gc)
scheme@(guile-user)> (map pointer->string $3)
$5 = ("Hello" "there!")
Is this correct, or am I just lucky here? What is certain is that holding a
reference to the data (only) does not work, as shown in the examples
in the 'pointed' email ...
David
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-06-30 12:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2019-06-30 20:05 ` Isaac Jurado
2019-06-30 12:51 ` Hans Åberg
2019-07-01 1:26 ` Mark H Weaver
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=20190630091732.0a6540ef@capac \
--to=david@altosw.be \
--cc=diptongo@gmail.com \
--cc=gdt@lexort.com \
--cc=guile-devel@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).