Subject: bug#18136: 24.4.50; crash in redisplay when calling load-theme

From: Eli Zaretskii <[email-masked]>
Date: Thu, 31 Jul 2014 20:55:11 +0300

> Date: Thu, 31 Jul 2014 18:53:33 +0200
> From: martin rudalics <[email-masked]>
> CC: [email-masked], [email-masked]
> 
>  >> But I don't really understand about `set-frame-height' and friends on a
>  >> TTY and what they are supposed to do.  Should these be allowed to change
>  >> the frame size?
>  >
>  > Yes.
> 
> In the sense that the frame can get larger or smaller than the terminal
> window?

Yes.

> So we internally work with say 100 frame lines although the
> terminal can display only 80?

That will not work well (you can try and see yourself).  But the
opposite, i.e. having a 80-line frame on a 100-line terminal, is quite
usable.  In fact, some people seem to use that to have minibuffer-only
frames on a TTY.

>  >> Now about the
>  >>
>  >>       change_frame_size (XFRAME (selected_frame),
>  >>                          FrameCols (t->display_info.tty),
>  >>                          FrameRows (t->display_info.tty)
>  >> 		       - FRAME_MENU_BAR_LINES (f), 0, 0, 1, 0);
>  >>
>  >> call in init_display.  What precisely is this supposed to accomplish?
>  >
>  > Allocate the glyph matrices, at the very least, I guess.
> 
> OK.  BTW doesn't adjust_frame_glyphs_for_frame_redisplay count the
> menubar specially?

It knows about it, yes:

  /* Add in menu bar lines, if any.  */
  matrix_dim.height += top_window_y;

>  >> Back to init_display and the question I asked earlier: Why should the
>  >> subsequent adjust_frame_size call do
>  >>
>  >>         if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
>  >> 	FrameRows (FRAME_TTY (f)) = new_lines;
>  >>
>  >> here?
>  >
>  > Maybe it shouldn't, when called from init_display.  But we should at
>  > least leave an eassert there, in case we overlook something.
> 
> Can I call adjust_frame_size directly from init_display?

If all the rest is a no-op, yes, why not?

> IIUC FrameRows is the height of the terminal window and when I change
> the height of that window I want to change the height of the Emacs frame
> as well via handle_window_change_signal/change_frame_size.  This means I
> can set FrameCols where I do it now because whenever I change the size
> of the outer frame that of the frame's windows changes too.

Sorry, you lost me here.  First, you use "window" in several
overloaded meanings, or so it seems.  And second, why are we suddenly
talking about SIGWINCH and its handling?  This is not the scenario in
which this bug happens.

> Still it seems to me contrived to set FrameCols/FrameRows when adjusting
> the sizes of a frame's windows.

How else will FrameCols/FrameRows be updated if the user calls
set-frame-size and its ilk?

> And setting FrameCols when called from init_display is certainly not
> TRT IMHO.

If you are sure they are already set by then, OK.  Evidently, in this
case, the call to change_frame_size tried to decrease the frame size
by one line, so something is still out of sync somewhere.

>  > In any case, this begs the question: why do you at all call
>  > adjust_frame_size in this case, if the frame already has the required
>  > size?  I think the answer is that adjust_frame_size does something
>  > else: it calls adjust_frame_glyphs.  That call is required at
>  > init_display time for obvious reasons, but it is inside
>  > adjust_frame_size which is only called when the frame size changes,
>  > which sounds like a contradiction in the design.
> 
> Think of turning off/on the menubar of a maximized frame.  In this case
> I do not change the size of the frame either.  Yet I have to call
> adjust_frame_glyphs.

Is that supposed to be the answer to my question, or just say what I
said in other words?

> BTW in an earlier mail you said that
> 
>  > E.g., with your suggested semantics, what would you expect from this:
>  >
>  >   emacs -Q
>  >   M-: (frame-height) RET
>  >   M-x menu-bar-mode RET
>  >   M-: (frame-height) RET
>  >
>  > Would you expect to see the 2 results of frame-height identical or
>  > different?
>  >
>  > The current trunk displays 2 identical results, and actually resizes
>  > the root window to be consistent with that, so that there's an unused
>  > empty line below the echo area.  Is that intended?  It looks like a
>  > misfeature to me.
> 
> Where and how did you get that?  I can't reproduce it here.

I can reproduce it with the current trunk on GNU/Linux where I invoke
"emacs -Q -nw" via PuTTY.  The resize is _after_ I invoke frame-height
the second time, which is already the sign of a problem.

>  >> Now please tell me one thing: Which calls of change_frame_size or
>  >> adjust_frame_size _should_ set FrameRows or FrameCols
>  >
>  > Any calls that actually change the frame size.
> 
> Is turning off/on the TTY menubar one of them?

No.

> Wouldn't it be principally cleaner if we set FrameCols and FrameRows
> after calling get_tty_size only?

You can't.  get_tty_size reports the _physical_ dimensions of the
terminal screen, so it cannot support set-frame-size and its ilk,
which leave the physical dimensions unaltered.