[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Freeze with specific evaluation in the modeline
From: |
Eli Zaretskii |
Subject: |
Re: Freeze with specific evaluation in the modeline |
Date: |
Tue, 03 Sep 2024 17:17:12 +0300 |
> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: emacs-devel@gnu.org
> Date: Mon, 02 Sep 2024 23:40:24 +0200
>
> On Mon, 02 Sep 2024 21:56:13 +0200 "Nicolas P. Rougier (inria)"
> <nicolas.rougier@inria.fr> wrote:
>
> > I've tried the following code (with Emacs -q, v30.0.60):
> >
> > (setq mode-line-format
> > '(:eval (if (window-in-direction 'down) "yes" "no")))
> >
> > and it somehow freezes Emacs even though menubar is still responsive and
> > I can quit through the menu. I'm not sure how to debug since I cannot
> > really interact anymore.
> >
> > Could anyone confirms the behavior?
>
> I can, and when I ran emacs under gdb and evaluated the above sexp, this
> immediately caused a segfault in pos_visible_p. I then typed bt full at
> the gdb prompt and the backtrace appeared to infloop; when I interrupted
> it, it was at frame #3935. Below is the backtrace up to the start of
> frame #48, which I think shows the loop.
It isn't a loop, it's infinite recursion. window-in-direction calls
posn-at-point, which calls display_mode_line, which again evaluates
the form, which calls window-in-direction...
Just don't do this, is all I can say. I don't see a way of protecting
against this without disabling useful features of :eval. Emacs gives
you enough rope to hang yourself, but don't hang yourself. The
variant below avoids infinite recursion, perhaps at a price of losing
accuracy in some corner cases:
(setq mode-line-format
'(:eval (let (mode-line-format)
(if (window-in-direction 'down) "yes" "no"))))
The :eval feature is inherently dangerous. The documentation of :eval
already warns about one possible danger of getting infinite recursion,
I will try to find a way to add this caveat as well.