Subject: Re: bug#56561: 29.0.50; Infloop in try_window

From: Po Lu <[email-masked]>
Date: Sat, 16 Jul 2022 14:42:09 +0800

Eli Zaretskii <[email-masked]> writes:

>   if (CONSP (Vx_max_tooltip_size)
>       && RANGED_FIXNUMP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
>       && RANGED_FIXNUMP (1, XCDR (Vx_max_tooltip_size), INT_MAX))
>     {
>       w->total_cols = XFIXNAT (XCAR (Vx_max_tooltip_size));
>       w->total_lines = XFIXNAT (XCDR (Vx_max_tooltip_size));
>     }
>   else
>     {
>       w->total_cols = 80;
>       w->total_lines = 40;
>     }
>
>   w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (tip_f);
>   w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (tip_f);
>   FRAME_TOTAL_COLS (tip_f) = WINDOW_TOTAL_COLS (w);
>   adjust_frame_glyphs (tip_f);

Hmm, right.  But what if Vx_max_tooltip_size makes the window too small
to hold the entire tooltip?

> Or maybe I don't understand what you mean by "the size can be changed
> by the window manager", please explain and show the code to which you
> allude.
>
> As for toolkits: we don't use this code when toolkit tooltips are
> used.

I wasn't talking about X specifically.  The code in nsfns.m calls
[NSWindow setFrame: display:], which can end up calling
adjust_frame_size if NS decides for whatever reason to resize the
tooltip frame.

But you're right.  It is called after we compute the window dimensions
and then call try_window.

> That would trigger unnecessarily, creating false positives.

How so?  We pass TRY_WINDOW_IGNORE_FONTS_CHANGE, so try_window can only
return 0 if the glyph matrices are too small.

> The situation that started this bug report is one such case: my fix
> will cause try_window to return zero in that case.  But if the entire
> text was processed and is in the glyph matrix, that zero return value
> doesn't mean a failure.

That isn't what the comment above try_window says about its return
value:

   Value is 1 if successful.  It is zero if fonts were loaded during
   redisplay which makes re-adjusting glyph matrices necessary, and -1
   if point would appear in the scroll margins.
   (We check the former only if TRY_WINDOW_IGNORE_FONTS_CHANGE is
   unset in FLAGS, and the latter only if TRY_WINDOW_CHECK_MARGINS is
   set in FLAGS.)