From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#26503: Local variables reclaimed early vs. finalizers Date: Wed, 19 Apr 2017 10:00:11 +0200 Message-ID: <87shl4esj8.fsf@igalia.com> References: <87a87islel.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1492588884 30558 195.159.176.226 (19 Apr 2017 08:01:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Apr 2017 08:01:24 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 26503@debbugs.gnu.org To: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Apr 19 10:01:11 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0kY3-0007hb-8s for guile-bugs@m.gmane.org; Wed, 19 Apr 2017 10:01:11 +0200 Original-Received: from localhost ([::1]:46246 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0kY9-0003zW-7G for guile-bugs@m.gmane.org; Wed, 19 Apr 2017 04:01:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0kXy-0003yi-Qa for bug-guile@gnu.org; Wed, 19 Apr 2017 04:01:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0kXu-0007j9-3a for bug-guile@gnu.org; Wed, 19 Apr 2017 04:01:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:57285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d0kXt-0007j5-Vl for bug-guile@gnu.org; Wed, 19 Apr 2017 04:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d0kXt-0004zI-NI for bug-guile@gnu.org; Wed, 19 Apr 2017 04:01:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 19 Apr 2017 08:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26503 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 26503-submit@debbugs.gnu.org id=B26503.149258882319111 (code B ref 26503); Wed, 19 Apr 2017 08:01:01 +0000 Original-Received: (at 26503) by debbugs.gnu.org; 19 Apr 2017 08:00:23 +0000 Original-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 Original-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 Original-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= Original-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) Original-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) In-Reply-To: <87a87islel.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Fri, 14 Apr 2017 23:56:50 +0200") X-Pobox-Relay-ID: 3A9B2832-24D6-11E7-951A-571C92A0D1B0-02397024!pb-sasl2.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8731 Archived-At: 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