Subject: bug#39977: 28.0.50; Unhelpful stack trace

From: Eli Zaretskii <[email-masked]>
Date: Mon, 23 Mar 2020 16:48:27 +0200

> Cc: [email-masked], [email-masked]
> From: martin rudalics <[email-masked]>
> Date: Sun, 22 Mar 2020 19:20:33 +0100
> 
> Once an initial frame has been created, Lisp code should be always able
> to rely on the truth of
> 
> (and (frame-live-p (selected-frame))
>       (window-live-p (selected-window))
>       (eq (frame-selected-window (selected-frame))
> 	 (selected-window)))

I agree.  But note that selected-frame could switch frames internally,
if the last selected frame is dead; as long as selected-frame also
adjusts the selected window, the above will still hold.

> (1) Let the redisplay code handle it.
> 
> (2) Let the frame and window management handle it by disallowing such
> operations while they are issued by the mode line or frame title
> processing code.
> 
> (3) Ignore it and let the frame/window management routines catch up with
> it later.
> 
> Using (1) way my initial idea.  The patch I proposed handles simple
> cases like Madhu's bug.  It will certainly not handle more sophisticated
> cases where, for example, an application kills two frames in a row.
> 
> (2) is by far the most simple and reliable approach but it will restrict
> applications in what they are allowed to do when processing a mode line
> or frame title.
> 
> (3) means that frame/window management proceeds in a non-deterministic
> fashion as long as it has not detected that its basic invariant has been
> violated.

I'm okay with having non-deterministic behavior triggered by code that
violates that invariant.  We will tell people who write such Lisp code
"if it hurts, don't do that".

>  > This isn't about trust.  This is about letting users' Lisp do anything
>  > they want as long as the results allow redisplay to continue after
>  > that Lisp returns.  I don't think it's right to disallow certain
>  > actions just because they _might_ cause problems.
> 
> You again care about redisplay only.

Only because the crashes we are discussing were in redisplay.  Not in
general.

>  >> If that's the reason, then SELECTED_FRAME can easily set selected_frame
>  >> to some live frame and continue.
>  >
>  > Something like that, yes.
> 
> I attach a patch that does that.  If you try it with a recipe like
> loading
> 
> 
> (defvar foo
>    '(:eval
>      (when (> (length (frame-list)) 1)
>        (delete-frame (next-frame)))))
> 
> (setq-default mode-line-format foo)
> 
> (make-frame)
> 
> 
> with emacs -Q you will see that while it works around the crash it still
> produces a
> 
> Wrong type argument: window-live-p, #<window 3>
> 
> error in redisplay.

That might not be the best solution, but it's "good enough" in my
book.  The programmer who writes such code deserves punishment, and an
error in redisplay that doesn't lock up Emacs (or does it?) is ample
punishment, IMO.

Thanks.