From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Emacs development discussions." Newsgroups: gmane.emacs.devel Subject: Re: unwind-protect within while-no-input Date: Sat, 25 May 2024 22:47:07 -0400 Message-ID: References: Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26428"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:QKre6v4ZIgZnIbtzzS4VGW3Qrzs= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun May 26 04:48:09 2024 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sB3vd-0006lv-2M for ged-emacs-devel@m.gmane-mx.org; Sun, 26 May 2024 04:48:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sB3up-0004Hk-Bd; Sat, 25 May 2024 22:47:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sB3uo-0004Hb-Ju for emacs-devel@gnu.org; Sat, 25 May 2024 22:47:18 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sB3um-0003AI-HI for emacs-devel@gnu.org; Sat, 25 May 2024 22:47:18 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1sB3ui-0005nv-J9 for emacs-devel@gnu.org; Sun, 26 May 2024 04:47:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:319569 Archived-At: > It seems like it's impossible right now to use unwind-protect robustly > in face of quits, because a quit triggered in the body forms of the > unwind-protect will also interrupt the unwind forms. I believe that is indeed the case. 🙁 > And there is no way to work around this, because binding inhibit-quit > in the unwind forms can *also* be interrupted. Yup. I have seen such problems when I hit `C-g` frantically to get out of some problematic state, and some of the repetitions end up happening while we're running the unwind forms. > Maybe there should be a version of unwind-protect which automatically > and atomically inhibits quit in the unwind forms? I tend to agree. I even considered that this should apply to all unwind forms, tho I suspect it would be too drastic, making it impossible to escape problems where the unwind form itself is stuck in an inf-loop. At the very least things like `C-g` should not be able to interrupt the unwinding of things like dynamically scoped let-bindings or `save-excursion`. Is there a bug-report associated to this thread? Maybe a "cheaper" answer for your specific problem is to make sure that once `while-no-input` has started a non-local exit (which it does with `throw`, IIRC), we mark "this while-no-input" as being done so it won't cause a nested exit while we process the unwind form of the original exit. E.g. with a patch like the one below? Would it fix your case? Stefan diff --git a/src/keyboard.c b/src/keyboard.c index 3551a77a9c9..c2c326f434c 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3801,7 +3816,10 @@ kbd_buffer_store_buffered_event (union buffered_input_event *event, as input, set quit-flag to cause an interrupt. */ if (!NILP (Vthrow_on_input) && !is_ignored_event (event)) - Vquit_flag = Vthrow_on_input; + { + Vquit_flag = Vthrow_on_input; + Vthrow_on_input = !nil; + } } /* Limit help event positions to this range, to avoid overflow problems. */