From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.devel Subject: Re: C calling Scheme and garbage collection Date: Sun, 30 Jun 2019 09:17:32 -0300 Message-ID: <20190630091732.0a6540ef@capac> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/33J0COQ2_nhhZ4OMVjydY_k"; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="264588"; mail-complaints-to="usenet@blaine.gmane.org" Cc: Isaac Jurado , guile-devel@gnu.org To: Greg Troxel Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Jun 30 14:18:04 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hhYmR-0016gQ-4U for guile-devel@m.gmane.org; Sun, 30 Jun 2019 14:18:03 +0200 Original-Received: from localhost ([::1]:44508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhYmQ-00045E-3L for guile-devel@m.gmane.org; Sun, 30 Jun 2019 08:18:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35533) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hhYmC-00044t-QZ for guile-devel@gnu.org; Sun, 30 Jun 2019 08:17:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hhYmA-0005sM-Ue for guile-devel@gnu.org; Sun, 30 Jun 2019 08:17:48 -0400 Original-Received: from maximusconfessor.all2all.org ([79.99.200.102]:60748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hhYm8-0005oF-VJ for guile-devel@gnu.org; Sun, 30 Jun 2019 08:17:46 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by maximusconfessor.all2all.org (Postfix) with ESMTP id 595191BE0092; Sun, 30 Jun 2019 14:17:41 +0200 (CEST) Original-Received: from maximusconfessor.all2all.org ([127.0.0.1]) by localhost (maximusconfessor.all2all.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id KPDOivC_N4aW; Sun, 30 Jun 2019 14:17:41 +0200 (CEST) Original-Received: from capac (unknown [179.210.16.250]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id 737D61BE0090; Sun, 30 Jun 2019 14:17:40 +0200 (CEST) In-Reply-To: X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 79.99.200.102 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19992 Archived-At: --Sig_/33J0COQ2_nhhZ4OMVjydY_k Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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 thr= ead, the one that lists a series of examples, and out of those, only the last exampl= e 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 p= ointer, but it seemed to me, after further local tests, that it is sufficient to ho= ld 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 =3D # scheme@(guile-user)> (parse-c-struct $2 (list '* '*)) $3 =3D (# #) scheme@(guile-user)> (map pointer->string $3) $4 =3D ("Hello" "there!") scheme@(guile-user)> (gc) scheme@(guile-user)> (map pointer->string $3) $5 =3D ("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 --Sig_/33J0COQ2_nhhZ4OMVjydY_k Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEhCJlRZtBM3furJHe83T9k6MFetcFAl0YqFwACgkQ83T9k6MF etcZKQf/XtuKkTDUWKnATISl7gm0YsW21yElBca/lV0QoSeHkbMGES5j4HnqbK9p oU6RGDxAINNs+XvwrT2N5PykELcdbHvj0R6rALbWpEzc1jCwsLdPAZkeQiIO6jGf 6W8WM5mF8KqeKCSGZwrEURGapBmZzAb9PpBQDRuHHWK+VYax2MNuaZM6fD/2sJ84 w/x80j/oB2BwhwNTRbQvlu2C7S7kPeIPcw6t7JRuyt772XLsnyMJNObdKeQ1v+8/ 28WC+R076PjnERBiRkvDfbaIB210D2Ws6dVNcMym39ME4M41/5csnmM42stqLYvA GJk4qZPP7ao0KXD+k7avfBD/TYTDpw== =xqea -----END PGP SIGNATURE----- --Sig_/33J0COQ2_nhhZ4OMVjydY_k--