From unknown Sat Sep 13 17:35:07 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#26503 <26503@debbugs.gnu.org> To: bug#26503 <26503@debbugs.gnu.org> Subject: Status: Local variables reclaimed early vs. finalizers Reply-To: bug#26503 <26503@debbugs.gnu.org> Date: Sun, 14 Sep 2025 00:35:07 +0000 retitle 26503 Local variables reclaimed early vs. finalizers reassign 26503 guile submitter 26503 ludo@gnu.org (Ludovic Court=C3=A8s) severity 26503 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 14 17:57:11 2017 Received: (at submit) by debbugs.gnu.org; 14 Apr 2017 21:57:11 +0000 Received: from localhost ([127.0.0.1]:47546 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cz9DL-00038N-0K for submit@debbugs.gnu.org; Fri, 14 Apr 2017 17:57:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:53443) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cz9DJ-00038B-1E for submit@debbugs.gnu.org; Fri, 14 Apr 2017 17:57:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cz9DD-00028Z-2l for submit@debbugs.gnu.org; Fri, 14 Apr 2017 17:57:03 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:41985) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cz9DC-00028F-VS for submit@debbugs.gnu.org; Fri, 14 Apr 2017 17:57:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cz9DB-0005hu-PG for bug-guile@gnu.org; Fri, 14 Apr 2017 17:57:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cz9D3-0001v9-9k for bug-guile@gnu.org; Fri, 14 Apr 2017 17:57:01 -0400 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:37089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cz9D3-0001v5-64 for bug-guile@gnu.org; Fri, 14 Apr 2017 17:56:53 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:58738 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1cz9D2-0000ya-J6 for bug-guile@gnu.org; Fri, 14 Apr 2017 17:56:52 -0400 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: bug-guile@gnu.org Subject: Local variables reclaimed early vs. finalizers X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 25 Germinal an 225 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Fri, 14 Apr 2017 23:56:50 +0200 Message-ID: <87a87islel.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Hello! Consider this code: --8<---------------cut here---------------start------------->8--- (use-modules (system foreign)) (define %table (make-weak-value-hash-table)) (define %abort (dynamic-func "abort" (dynamic-link))) (let ((ptr (make-pointer 123 %abort))) (display "hello\n") (gc)) --8<---------------cut here---------------end--------------->8--- Guile is free to collect =E2=80=98ptr=E2=80=99 when =E2=80=98gc=E2=80=99 is= called since it has become unreachable at that point; that=E2=80=99s what 2.2.0 does, as explained in =E2=80=98NEWS=E2=80=99. However, there=E2=80=99s a finalizer here so collecting =E2=80=98ptr=E2=80= =99 has an observable side effect. This side effect makes the semantic change visible: the =E2=80=9Cexpected=E2=80=9D semantics would be that =E2=80=98ptr=E2=80=99 is= not subject to GC while it=E2=80=99s in scope. (In 2.0 the finalizer is not called until =E2=80=98ptr=E2=80=99 is no longe= r in scope.) I=E2=80=99m not sure this counts as a bug, but it=E2=80=99s certainly a pit= fall when working with finalizers and the FFI. Thoughts? Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 04:00:23 2017 Received: (at 26503) by debbugs.gnu.org; 19 Apr 2017 08:00:23 +0000 Received: from localhost ([127.0.0.1]:55484 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0kXG-0004yB-O8 for submit@debbugs.gnu.org; Wed, 19 Apr 2017 04:00:22 -0400 Received: from pb-sasl2.pobox.com ([64.147.108.67]:52791 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0kXE-0004y3-SH for 26503@debbugs.gnu.org; Wed, 19 Apr 2017 04:00:21 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id 026E98220C; Wed, 19 Apr 2017 04:00:19 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=IbZ6sMEKKjcp ClXiBcvRkiA4Pzw=; b=S7PaQaZLOAnWbnFLaWjWbTfmiHtO0RZTDkkrUzxdpH+R tG0wjENCHTm3KZURNbRAxP3kf+MqZNwV0ww558t9Duu6rsWthaF9GbWc2+YHMnOP iRxBcfzWL0lswlIww8VPJqeBwGGa/ggKo4WmHG5g3evMDPv7GxmsP9DbzbXUxtM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; q=dns; s=sasl; b=iPoYTJ wzkeP3zmxhNmMQVLda6mLzkgAgp8ZUL40R0flqZ1hsEjHt9QWcA8b6WifVpfrQtb GRGUV5r2us4KM1b9vzxtd2+6rr7YyWrWIgWE/t+WEkIguCUQwyvMKpN5duI5QWvX Lzmx1/E8V05x0j0LN1CvTPjFNWiTsIuoHR8wA= Received: from pb-sasl2.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl2.pobox.com (Postfix) with ESMTP id E6AA28220B; Wed, 19 Apr 2017 04:00:18 -0400 (EDT) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl2.pobox.com (Postfix) with ESMTPSA id 213D382206; Wed, 19 Apr 2017 04:00:18 -0400 (EDT) From: Andy Wingo To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#26503: Local variables reclaimed early vs. finalizers References: <87a87islel.fsf@gnu.org> Date: Wed, 19 Apr 2017 10:00:11 +0200 In-Reply-To: <87a87islel.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Fri, 14 Apr 2017 23:56:50 +0200") Message-ID: <87shl4esj8.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: 3A9B2832-24D6-11E7-951A-571C92A0D1B0-02397024!pb-sasl2.pobox.com X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 26503 Cc: 26503@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) ludo@gnu.org (Ludovic Court=C3=A8s) writes: > Consider this code: > > (use-modules (system foreign)) > > (define %abort > (dynamic-func "abort" (dynamic-link))) > > (let ((ptr (make-pointer 123 %abort))) > (display "hello\n") > (gc)) > > Guile is free to collect =E2=80=98ptr=E2=80=99 when =E2=80=98gc=E2=80=99 = is called since it has become > unreachable at that point; that=E2=80=99s what 2.2.0 does, as explained in > =E2=80=98NEWS=E2=80=99. > > However, there=E2=80=99s a finalizer here so collecting =E2=80=98ptr=E2= =80=99 has an observable > side effect. This side effect makes the semantic change visible: the > =E2=80=9Cexpected=E2=80=9D semantics would be that =E2=80=98ptr=E2=80=99 = is not subject to GC while it=E2=80=99s > in scope. This would indicate that the user has erroneous expectations ;-) Note that here since (gc) is in tail position, ptr is in fact not protected in any way, even given this mental model, though with a single thread it may be that the collection actually happens later in 2.0 given that finalizers are run by asyncs. Also ptr is not protected during the "display" either, in 2.0; in 2.0 this "let" reduces to "begin" under peval since the ptr is not used. > (In 2.0 the finalizer is not called until =E2=80=98ptr=E2=80=99 is no lon= ger in scope.) > > I=E2=80=99m not sure this counts as a bug, but it=E2=80=99s certainly a p= itfall when > working with finalizers and the FFI. > > Thoughts? For me, I don't think this is a bug. Rather the contrary, as it's more in spirit with safe-for-space principle that a continuation should only keep alive those values that it uses; any other data should be available for the GC to reclaim. In any case, I think this manual section treats the problem adequately, for me at least: https://www.gnu.org/software/guile/manual/html_node/Foreign-Object-Memory= -Management.html Would you like to add something there? Andy From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 05:50:35 2017 Received: (at 26503) by debbugs.gnu.org; 19 Apr 2017 09:50:35 +0000 Received: from localhost ([127.0.0.1]:55564 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0mFv-0007co-Km for submit@debbugs.gnu.org; Wed, 19 Apr 2017 05:50:35 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35719) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0mFu-0007cc-6t for 26503@debbugs.gnu.org; Wed, 19 Apr 2017 05:50:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0mFm-00015M-0q for 26503@debbugs.gnu.org; Wed, 19 Apr 2017 05:50:29 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RP_MATCHES_RCVD autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:42970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0mFl-00015A-Te; Wed, 19 Apr 2017 05:50:25 -0400 Received: from reverse-83.fdn.fr ([80.67.176.83]:37562 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1d0mFl-0006zN-83; Wed, 19 Apr 2017 05:50:25 -0400 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Andy Wingo Subject: Re: bug#26503: Local variables reclaimed early vs. finalizers References: <87a87islel.fsf@gnu.org> <87shl4esj8.fsf@igalia.com> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 30 Germinal an 225 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-unknown-linux-gnu Date: Wed, 19 Apr 2017 11:50:22 +0200 In-Reply-To: <87shl4esj8.fsf@igalia.com> (Andy Wingo's message of "Wed, 19 Apr 2017 10:00:11 +0200") Message-ID: <87tw5krajl.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 26503 Cc: 26503@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -5.0 (-----) Andy Wingo skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: > >> Consider this code: >> >> (use-modules (system foreign)) >> >> (define %abort >> (dynamic-func "abort" (dynamic-link))) >> >> (let ((ptr (make-pointer 123 %abort))) >> (display "hello\n") >> (gc)) >> >> Guile is free to collect =E2=80=98ptr=E2=80=99 when =E2=80=98gc=E2=80=99= is called since it has become >> unreachable at that point; that=E2=80=99s what 2.2.0 does, as explained = in >> =E2=80=98NEWS=E2=80=99. >> >> However, there=E2=80=99s a finalizer here so collecting =E2=80=98ptr=E2= =80=99 has an observable >> side effect. This side effect makes the semantic change visible: the >> =E2=80=9Cexpected=E2=80=9D semantics would be that =E2=80=98ptr=E2=80=99= is not subject to GC while it=E2=80=99s >> in scope. > > This would indicate that the user has erroneous expectations ;-) > > Note that here since (gc) is in tail position, ptr is in fact not > protected in any way, even given this mental model, though with a single > thread it may be that the collection actually happens later in 2.0 given > that finalizers are run by asyncs. Also ptr is not protected during the > "display" either, in 2.0; in 2.0 this "let" reduces to "begin" under > peval since the ptr is not used. Indeed (in practice =E2=80=98ptr=E2=80=99 would happen to be finalized late= r, but that=E2=80=99s =E2=80=9Cout of luck=E2=80=9D.) >> (In 2.0 the finalizer is not called until =E2=80=98ptr=E2=80=99 is no lo= nger in scope.) >> >> I=E2=80=99m not sure this counts as a bug, but it=E2=80=99s certainly a = pitfall when >> working with finalizers and the FFI. >> >> Thoughts? > > For me, I don't think this is a bug. Rather the contrary, as it's more > in spirit with safe-for-space principle that a continuation should only > keep alive those values that it uses; any other data should be available > for the GC to reclaim. > > In any case, I think this manual section treats the problem adequately, > for me at least: > > https://www.gnu.org/software/guile/manual/html_node/Foreign-Object-Memo= ry-Management.html > > Would you like to add something there? Hmm, I don=E2=80=99t think so (great section, BTW). I need to chew a bit more on this, but the conclusion is probably that my expectations were incorrect, indeed. :-) Thanks, Ludo=E2=80=99. From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 19 08:24:11 2017 Received: (at 26503-done) by debbugs.gnu.org; 19 Apr 2017 12:24:11 +0000 Received: from localhost ([127.0.0.1]:55630 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0oeY-0004cz-R5 for submit@debbugs.gnu.org; Wed, 19 Apr 2017 08:24:10 -0400 Received: from pb-sasl1.pobox.com ([64.147.108.66]:58510 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0oeW-0004cq-1Q for 26503-done@debbugs.gnu.org; Wed, 19 Apr 2017 08:24:08 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 6D17481663; Wed, 19 Apr 2017 08:24:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type:content-transfer-encoding; s=sasl; bh=2jge0ZLiFq3T Xs8PkeGXdyJQU30=; b=DNnyztpndO3mDp70/LrAHt1woErhl3S2K6vuzubRc76j CF/RnhymL0/i1/ybm1mNaieWFMl4Sb/OcCN82qg92hFXozi1j4StGZ25Gie81Q4I 6TTBwfdGWlCA8S4RuofB7RoYy3v8BR3dGzssooVjCAqYT6ueTPSvYhJgLYNJU74= Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1]) by pb-sasl1.pobox.com (Postfix) with ESMTP id 66B3181662; Wed, 19 Apr 2017 08:24:06 -0400 (EDT) Received: from rusty (unknown [88.160.190.192]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by pb-sasl1.pobox.com (Postfix) with ESMTPSA id ACF1781661; Wed, 19 Apr 2017 08:24:05 -0400 (EDT) From: Andy Wingo To: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Subject: Re: bug#26503: Local variables reclaimed early vs. finalizers References: <87a87islel.fsf@gnu.org> <87shl4esj8.fsf@igalia.com> <87tw5krajl.fsf@gnu.org> Date: Wed, 19 Apr 2017 14:23:59 +0200 In-Reply-To: <87tw5krajl.fsf@gnu.org> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?= =?utf-8?Q?s?= message of "Wed, 19 Apr 2017 11:50:22 +0200") Message-ID: <87y3uwoaao.fsf@igalia.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Pobox-Relay-ID: 148D63A6-24FB-11E7-B6FF-07D2064AB293-02397024!pb-sasl1.pobox.com X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 26503-done Cc: 26503-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.7 (/) On Wed 19 Apr 2017 11:50, ludo@gnu.org (Ludovic Court=C3=A8s) writes: > I need to chew a bit more on this, but the conclusion is probably that > my expectations were incorrect, indeed. :-) OK I close this bug in the meantime then :) Feel free to reopen if there is a thing to do! Andy From unknown Sat Sep 13 17:35:07 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 18 May 2017 11:24:03 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator