X-Loop: help-debbugs@HIDDEN
Subject: bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect
Resent-From: Markus Triska <triska@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Wed, 13 Jul 2016 06:29:01 +0000
Resent-Message-ID: <handler.23963.B.146839133925633 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: report 23963
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords:
To: 23963 <at> debbugs.gnu.org
X-Debbugs-Original-To: bug-gnu-emacs@HIDDEN
Received: via spool by submit <at> debbugs.gnu.org id=B.146839133925633
(code B ref -1); Wed, 13 Jul 2016 06:29:01 +0000
Received: (at submit) by debbugs.gnu.org; 13 Jul 2016 06:28:59 +0000
Received: from localhost ([127.0.0.1]:48971 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1bNDfG-0006fM-Ps
for submit <at> debbugs.gnu.org; Wed, 13 Jul 2016 02:28:58 -0400
Received: from eggs.gnu.org ([208.118.235.92]:35371)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <triska@HIDDEN>) id 1bNDfF-0006f9-2Q
for submit <at> debbugs.gnu.org; Wed, 13 Jul 2016 02:28:57 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from <triska@HIDDEN>) id 1bNDf8-00089r-S7
for submit <at> debbugs.gnu.org; Wed, 13 Jul 2016 02:28:51 -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 autolearn=disabled
version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:44280)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from <triska@HIDDEN>) id 1bNDf8-00089g-P1
for submit <at> debbugs.gnu.org; Wed, 13 Jul 2016 02:28:50 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:54564)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from <triska@HIDDEN>) id 1bNDf6-0001uK-FM
for bug-gnu-emacs@HIDDEN; Wed, 13 Jul 2016 02:28:49 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from <triska@HIDDEN>) id 1bNDf2-00089H-84
for bug-gnu-emacs@HIDDEN; Wed, 13 Jul 2016 02:28:47 -0400
Received: from metalevel.at ([78.46.218.83]:41316)
by eggs.gnu.org with esmtp (Exim 4.71)
(envelope-from <triska@HIDDEN>) id 1bNDf2-00089A-14
for bug-gnu-emacs@HIDDEN; Wed, 13 Jul 2016 02:28:44 -0400
Received: from dawn.meta (localhost.localdomain [127.0.0.1])
by metalevel.at (Postfix) with ESMTP id 8FD91A05DE
for <bug-gnu-emacs@HIDDEN>; Wed, 13 Jul 2016 08:28:42 +0200 (CEST)
Received: by dawn.meta (Postfix, from userid 501)
id 092571AA32D0; Wed, 13 Jul 2016 08:28:45 +0200 (CEST)
From: Markus Triska <triska@HIDDEN>
Date: Wed, 13 Jul 2016 08:28:45 +0200
Message-ID: <m2d1mif3vm.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
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-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -5.0 (-----)
The manual entry of `unwind-protect' shows an example whose essence is:
(unwind-protect
(progn
(setq process (ftp-...))
;; use process
(delete-process process))
It adds the following important explanation:
This example has a small [sic] bug: if the user types `C-g' to quit,
and the quit happens immediately after the function `ftp-...'
returns but before the variable `process' is set, *the process will
not be killed*. There is no easy way to fix this bug, but at least
it is very unlikely.
Would it be good to make such resource leak *impossible* instead? This
seems quite desirable and could be done with a complementing primitive.
Please consider a new primitive `setup-unwind-protect' with 3 arguments:
1. SETUPFORM, called in such a way that it *cannot be interrupted*
2. BODYFORM, like in unwind-protect, called after SETUPFORM
3. UNWINDFORMS, like in unwind-protect
With this primitive, we could write the example above as:
(setup-unwind-protect
(setq process (ftp-...))
(progn
;; use process ...
(delete-process process))
Please consider adding such a construct to Emacs.
A precedence for such a construct is setup_call_cleanup/3 which appears
in the Prolog ISO draft standard and is already included in many systems:
https://www.complang.tuwien.ac.at/ulrich/iso-prolog/N215
Thank you and all the best!
Markus
In GNU Emacs 25.0.95.4 (x86_64-apple-darwin15.5.0, X toolkit, Xaw scroll bars)
of 2016-07-05 built on mt-imac
Repository revision: e3b039d1a0e611d6619ed3ce67d125160d644ebc
Windowing system distributor 'The X.Org Foundation', version 11.0.11502000
Configured using:
'configure --without-ns CFLAGS=-I/opt/local/include
LDFLAGS=-L/opt/local/lib'
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK GSETTINGS NOTIFY ACL GNUTLS
LIBXML2 FREETYPE XFT ZLIB TOOLKIT_SCROLL_BARS LUCID X11
Important settings:
value of $LANG: en_US.UTF-8
locale-coding-system: utf-8-unix
Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) Content-Type: text/plain; charset=utf-8 X-Loop: help-debbugs@HIDDEN From: help-debbugs@HIDDEN (GNU bug Tracking System) To: Markus Triska <triska@HIDDEN> Subject: bug#23963: Acknowledgement (25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect) Message-ID: <handler.23963.B.146839133925633.ack <at> debbugs.gnu.org> References: <m2d1mif3vm.fsf@HIDDEN> X-Gnu-PR-Message: ack 23963 X-Gnu-PR-Package: emacs Reply-To: 23963 <at> debbugs.gnu.org Date: Wed, 13 Jul 2016 06:29:01 +0000 Thank you for filing a new bug report with debbugs.gnu.org. This is an automatically generated reply to let you know your message has been received. Your message is being forwarded to the package maintainers and other interested parties for their attention; they will reply in due course. Your message has been sent to the package maintainer(s): bug-gnu-emacs@HIDDEN If you wish to submit further information on this problem, please send it to 23963 <at> debbugs.gnu.org. Please do not send mail to help-debbugs@HIDDEN unless you wish to report a problem with the Bug-tracking system. --=20 23963: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D23963 GNU Bug Tracking System Contact help-debbugs@HIDDEN with problems
X-Loop: help-debbugs@HIDDEN
Subject: bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect
Resent-From: Stefan Monnier <monnier@HIDDEN>
Original-Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
Resent-CC: bug-gnu-emacs@HIDDEN
Resent-Date: Sat, 27 Jan 2018 21:18:02 +0000
Resent-Message-ID: <handler.23963.B23963.15170878461561 <at> debbugs.gnu.org>
Resent-Sender: help-debbugs@HIDDEN
X-GNU-PR-Message: followup 23963
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords:
To: Markus Triska <triska@HIDDEN>
Cc: 23963 <at> debbugs.gnu.org
Received: via spool by 23963-submit <at> debbugs.gnu.org id=B23963.15170878461561
(code B ref 23963); Sat, 27 Jan 2018 21:18:02 +0000
Received: (at 23963) by debbugs.gnu.org; 27 Jan 2018 21:17:26 +0000
Received: from localhost ([127.0.0.1]:45541 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
id 1efXqn-0000P7-Of
for submit <at> debbugs.gnu.org; Sat, 27 Jan 2018 16:17:25 -0500
Received: from chene.dit.umontreal.ca ([132.204.246.20]:52753)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from <monnier@HIDDEN>) id 1efXqk-0000Oy-O4
for 23963 <at> debbugs.gnu.org; Sat, 27 Jan 2018 16:17:24 -0500
Received: from ceviche.home (lechon.iro.umontreal.ca [132.204.27.242])
by chene.dit.umontreal.ca (8.14.7/8.14.1) with ESMTP id w0RLHJdo012392;
Sat, 27 Jan 2018 16:17:20 -0500
Received: by ceviche.home (Postfix, from userid 20848)
id 95A296629F; Sat, 27 Jan 2018 16:17:19 -0500 (EST)
From: Stefan Monnier <monnier@HIDDEN>
Message-ID: <jwvlggjnh6u.fsf-monnier+bug#23963@HIDDEN>
References: <m2d1mif3vm.fsf@HIDDEN>
Date: Sat, 27 Jan 2018 16:17:19 -0500
In-Reply-To: <m2d1mif3vm.fsf@HIDDEN> (Markus Triska's message of "Wed,
13 Jul 2016 08:28:45 +0200")
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain
X-NAI-Spam-Flag: NO
X-NAI-Spam-Threshold: 5
X-NAI-Spam-Score: 0
X-NAI-Spam-Rules: 2 Rules triggered
EDT_SA_DN_PASS=0, RV6209=0
X-NAI-Spam-Version: 2.3.0.9418 : core <6209> : inlines <6344> : streams
<1777278> : uri <2580824>
X-Spam-Score: -1.3 (-)
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>,
<mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.3 (-)
Markus Triska <triska@HIDDEN> writes:
> With this primitive, we could write the example above as:
>
> (setup-unwind-protect
> (setq process (ftp-...))
> (progn
> ;; use process ...
> (delete-process process))
Given my dislike of `setq` I'd rather use something else.
This said, we also have another problem: if the user hits C-g twice
in a row, the second may interrupt the `delete-process` itself.
So I think what we "really" want is more like
(let ((oi inhibit-quit)
(inhibit-quit t))
(let ((process (ftp-...)))
(unwind-protect
(let ((inhibit-quit oi))
..use process..)
(delete-process process))))
At the same time, any function whose name starts with "ftp-" is likely
a bad candidate for running it in a context where it can't be
interrupted (it's likely that in various circumstances it could hang, in
which case the user should be able to hit C-g).
Stefan
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.