From unknown Sun Jun 15 08:37:55 2025 X-Loop: help-debbugs@gnu.org Subject: bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect Resent-From: Markus Triska Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 13 Jul 2016 06:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 23963 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 23963@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@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 ) id 1bNDfG-0006fM-Ps for submit@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 ) id 1bNDfF-0006f9-2Q for submit@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 ) id 1bNDf8-00089r-S7 for submit@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 ) id 1bNDf8-00089g-P1 for submit@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 ) id 1bNDf6-0001uK-FM for bug-gnu-emacs@gnu.org; Wed, 13 Jul 2016 02:28:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bNDf2-00089H-84 for bug-gnu-emacs@gnu.org; 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 ) id 1bNDf2-00089A-14 for bug-gnu-emacs@gnu.org; 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 ; 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 Date: Wed, 13 Jul 2016 08:28:45 +0200 Message-ID: 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@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 (-----) 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 From unknown Sun Jun 15 08:37:55 2025 X-Loop: help-debbugs@gnu.org Subject: bug#23963: 25.0.95; Feature request: setup-unwind-protect, complementing unwind-protect Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Jan 2018 21:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 23963 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Markus Triska Cc: 23963@debbugs.gnu.org Received: via spool by 23963-submit@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 ) id 1efXqn-0000P7-Of for submit@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 ) id 1efXqk-0000Oy-O4 for 23963@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 Message-ID: References: Date: Sat, 27 Jan 2018 16:17:19 -0500 In-Reply-To: (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@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: -1.3 (-) Markus Triska 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