Subject: bug#57804: An infinite loop in a `fontify-region' function causes Emacs to hang indefinitely

From: Paul Pogonyshev <[email-masked]>
Date: Thu, 15 Sep 2022 23:17:25 +0200

>>> No, if your function is called inside fontification-functions, you will
>>> not have to monitor Emacs sources, your code will use a single tag,
>>> namely 'fontification-functions.
>>
>> So, I will be able to unlock?
>
> Yes.

Good.

> > Wouldn't something like [...] not be much more robust?
>
> Definitely not.

But why? If you allow to lift restrictions, why not make it easy to
do? Call the variable/function that achieves this with a 100-character
name, brand the programmer an idiot in the name or documentation -
whatever. Don't advertise it in the manual, maybe add two lines
somewhere in a dark corner, repeating that only morons would use
it. But please, add something generic and simple to use.

Logview needs to temporarily cancel restrictions in _practically all_
its function. In the branch I see code like this:

    narrow_to_region_locked (make_fixnum (get_narrowed_begv (w, PT)),
                             make_fixnum (get_narrowed_zv (w, PT)),
                             hook);
                             ^^^^

So, suppose something in that hook (maybe even not installed by
Logview itself, e.g. by a minor mode or by the user: it is common to
have `add-hook' in Emacs initialization code) calls a function from
Logview. Now, that function from Logview does

    (please-widen-i-cant-work-with-locked-narrowing ...)

It, presumably, cannot know the tag used to install locked narrowing.
Will it be able to temporarily lift _any and all_ locked narrowing or
not? It probably won't freeze Emacs even if falling into an infinite
loop, likely there are not so many non-bugs like the one in this
thread, where misbehaving code can make Emacs hang irrepairably. But
still, if restrictions are not lifted, Logview function will likely
produce some incorrect result, require C-g to abort, or die with an
error.

Will the knowledge of the tag be required, as a sort of a "password",
to lift narrowing restrictions, or not?

Paul

On Thu, 15 Sept 2022 at 22:44, Gregory Heytings <[email-masked]>
wrote:

>
> >> No, if your function is called inside fontification-functions, you will
> >> not have to monitor Emacs sources, your code will use a single tag,
> >> namely 'fontification-functions.
> >
> > So, I will be able to unlock?
> >
>
> Yes.
>
> >
> > Let Logview behave against your recommendations. And then, when the
> > users discover how crappy and unresponsive it is, as a result, compared
> > to everything else, they will just uninstall the package and use
> > something better.
> >
>
> Given that you will be able to unlock, that will be possible.
>