From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Paul Pogonyshev Newsgroups: gmane.emacs.bugs Subject: bug#57804: An infinite loop in a `fontify-region' function causes Emacs to hang indefinitely Date: Thu, 15 Sep 2022 23:49:10 +0200 Message-ID: References: <87pmfx6h7y.fsf@gnus.org> <2b58b8f5429a6e3aecda@heytings.org> <834jx85tyv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000ef045705e8be3768" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9094"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , 57804@debbugs.gnu.org, Lars Ingebrigtsen To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 15 23:50:12 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1oYwkO-00025i-6K for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Sep 2022 23:50:12 +0200 Original-Received: from localhost ([::1]:52636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oYwkM-0006nA-Ir for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Sep 2022 17:50:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50794) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oYwkF-0006n0-3O for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 17:50:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42489) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oYwkE-0000nH-QV for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 17:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oYwkE-0000OR-C9 for bug-gnu-emacs@gnu.org; Thu, 15 Sep 2022 17:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Pogonyshev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Sep 2022 21:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57804 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: wontfix Original-Received: via spool by 57804-submit@debbugs.gnu.org id=B57804.16632785731443 (code B ref 57804); Thu, 15 Sep 2022 21:50:02 +0000 Original-Received: (at 57804) by debbugs.gnu.org; 15 Sep 2022 21:49:33 +0000 Original-Received: from localhost ([127.0.0.1]:59421 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYwjk-0000NC-UX for submit@debbugs.gnu.org; Thu, 15 Sep 2022 17:49:33 -0400 Original-Received: from mail-ed1-f44.google.com ([209.85.208.44]:37548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oYwjh-0000My-DU for 57804@debbugs.gnu.org; Thu, 15 Sep 2022 17:49:30 -0400 Original-Received: by mail-ed1-f44.google.com with SMTP id a41so17083889edf.4 for <57804@debbugs.gnu.org>; Thu, 15 Sep 2022 14:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=6ALit5UQwF1/YC4qBRaPrPbNkDU0I6Ax38Mzt7SUCLw=; b=MyD85cBDEGJtSR139+Mwv09rdVs18ipc7BHXcs8vk/xPLIkOAF7P1F1mkqo84s2xTj 8R5sKsU5NUG8wcXg2pAuITHvO4Cb4KFLPGSxYij9YdaPHrmvAvdrvcrjumIS0BGAHxHZ sZpAd5dtSM/DKuHIeejkqC1xbKnrMhwTIdvUSlZmxnz7Cn739U0K8h7qRmV/JCglkEfp 59nKcFn+NI3qr6+dUoVh0eGIuWPwi1sIS7PuHFXFjX6SuvzSHjyB7VvlNbaCwlaFNuLJ 4ZAiYefx1segMsMWdu9l05HZjcwMkF7z+wgHm2vTF61q5RTZnylEqh5rZ23OGKRL6RJo XWCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=6ALit5UQwF1/YC4qBRaPrPbNkDU0I6Ax38Mzt7SUCLw=; b=bcOPDdtEnbkG986Kqk6sLyRDkMHp1DItsOFdtD2tQWM0A/SPu+Nk+rkcKQb+yU7H9y 5MAtCpkriOshwgJJLhrxrjQx/9GU+EqN5HwKGrV0s2XZHNxe+xtoLYJXEaYwTo+Pj0WD +Nmpmznvsv0Zg6AqO3ZMCx8oRQDuhk/+/oKUyoYVBHVUmeG80WmcpQtxXehW0N+bUp9H fqkaYWaVfeXxf/fjJOX/L0beBmonYKMoyMHv8G24LSIRpD/COqh7uQ33hsagfgv2z7L4 KKpBYTu48bK5W7F5dHFrP6G/vIr50asza1Fu7ZVS14f/5gz4FWt2uJkJMpgLiCPx09oC M0tQ== X-Gm-Message-State: ACrzQf0e7ibqbgrbXkzgYXVpGSIAElKz7xynlM4Obrikz8zXQ6tvHRX+ F4R5IbquTVDbNyneLMdolF9XTxH+Q5AHYrkTgA== X-Google-Smtp-Source: AMsMyM6pXPCRsERVv2JA9R1QQNp6q8NsILYi3KIROBsFuZNgtXgzbJ7oYe4Qz4EFK1KYNyFb0eaNiA1jg9vwH7Zj13U= X-Received: by 2002:a05:6402:43cf:b0:450:eae1:c9d3 with SMTP id p15-20020a05640243cf00b00450eae1c9d3mr1525091edc.231.1663278563393; Thu, 15 Sep 2022 14:49:23 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:242654 Archived-At: --000000000000ef045705e8be3768 Content-Type: text/plain; charset="UTF-8" > It can do so (or more precisely will be able to do so) by calling > narrowing-unlock with the appropriate tag, which IIUC correctly is, in > your case, 'fontification-functions. OK, let me rewrite this in a bit more details. Here are some quotes from the C code in the branch: safe_run_hooks_maybe_narrowed (Qpre_command_hook, XWINDOW (selected_window)); ... safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w) { ... if (current_buffer->long_line_optimizations_p) narrow_to_region_locked (make_fixnum (get_narrowed_begv (w, PT)), make_fixnum (get_narrowed_zv (w, PT)), hook); Note how `hook' becomes `tag', i.e. narrowing is locked with tag `pre-command-hook' _in this case_. According to the code, it can also be locked with a few others, e.g. `post-command-hook'. Now, user writes in his `init.el' sth. like: (add-hook 'pre-command-hook (lambda () (when (eq major-mode 'logview-mode) (logview-do-bla-bla-bla)))) I don't know why, this is a hypothetical, but fairly realistic situation, right? Now, let's say function `logview-do-bla-bla-bla' cannot work with narrowed buffer (half of functions in Logview cannot). So, as a first step it does something like this: (save-restriction (widen) ... ) For this to keep working in Emacs 29, I will need to replace `(widen)' with I-don't-yet-know-what. But _I don't know the tag_. That's the problem. The function is called from somewhere I have no control, it can be bound to any hook that does install locked narrowing with some tag or maybe does not - I have no way to know that. Will I be able to lift locked narrowing restrictions without knowing the tag? Paul On Thu, 15 Sept 2022 at 23:32, Gregory Heytings wrote: > > > > > Logview needs to temporarily cancel restrictions in _practically all_ > > its function. > > > > It can do so (or more precisely will be able to do so) by calling > narrowing-unlock with the appropriate tag, which IIUC correctly is, in > your case, 'fontification-functions. I don't see why you would need > anything else, especially given that a general mechanism to disable locked > narrowing everywhere is already available for users who, like you, don't > care about long lines. > --000000000000ef045705e8be3768 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> It can do so (or more precisely will be able to do so= ) by calling
> narrowing-unlock with the appropriate tag, which IIUC = correctly is, in
> your case, 'fontification-functions.

OK= , let me rewrite this in a bit more details. Here are some quotes
from t= he C code in the branch:

=C2=A0 =C2=A0 safe_run_hooks_maybe_narrowed= (Qpre_command_hook,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0XWINDOW (selected_window));

=C2=A0 =C2=A0 ...

=C2=A0 =C2= =A0 safe_run_hooks_maybe_narrowed (Lisp_Object hook, struct window *w)
= =C2=A0 =C2=A0 {
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 =C2=A0 if (cur= rent_buffer->long_line_optimizations_p)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 n= arrow_to_region_locked (make_fixnum (get_narrowed_begv (w, PT)),
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0make_fixnum (get_narrowed_zv (w, PT))= ,
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0hook);

Note how `hoo= k' becomes `tag', i.e. narrowing is locked with tag
`pre-command= -hook' _in this case_. According to the code, it can also
be locked = with a few others, e.g. `post-command-hook'.

Now, user writes in= his `init.el' sth. like:

=C2=A0 =C2=A0 (add-hook 'pre-comma= nd-hook (lambda ()
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (e= q major-mode 'logview-mode)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 (logview-do-bla-bla-bla))))

I don't know why, this= is a hypothetical, but fairly realistic
situation, right?

Now, l= et's say function `logview-do-bla-bla-bla' cannot work with
narr= owed buffer (half of functions in Logview cannot).=C2=A0 So, as a first
= step it does something like this:

=C2=A0 =C2=A0 (save-restriction=C2=A0 =C2=A0 =C2=A0 (widen)
=C2=A0 =C2=A0 =C2=A0 ...
=C2=A0 =C2=A0 = =C2=A0 )

For this to keep working in Emacs 29, I will need to replac= e `(widen)'
with I-don't-yet-know-what.=C2=A0 But _I don't k= now the tag_.=C2=A0 That's the
problem.=C2=A0 The function is called= from somewhere I have no control, it
can be bound to any hook that does= install locked narrowing with some
tag or maybe does not - I have no wa= y to know that.

Will I be able to lift locked narrowing restrictions= without knowing
the tag?

Paul

On Thu, 15 Sept 2022 at 23:32, = Gregory Heytings <gregory@heytin= gs.org> wrote:

>
> Logview needs to temporarily cancel restrictions in _practically all_ =
> its function.
>

It can do so (or more precisely will be able to do so) by calling
narrowing-unlock with the appropriate tag, which IIUC correctly is, in
your case, 'fontification-functions.=C2=A0 I don't see why you woul= d need
anything else, especially given that a general mechanism to disable locked =
narrowing everywhere is already available for users who, like you, don'= t
care about long lines.
--000000000000ef045705e8be3768--