Subject: bug#13007: 24.3.50; emacs_backtrace.txt

From: Dmitry Antipov <[email-masked]>
Date: Fri, 30 Nov 2012 19:50:57 +0400

On 11/30/2012 01:53 PM, Eli Zaretskii wrote:

> OK.  So what do you suggest, in practical terms?  Are you saying that
> we should use BUF_MODIFF(XBUFFER (w->buffer)) instead of MODIFF and
> BUF_OVERLAY_MODIFF(XBUFFER (w->buffer)) instead of OVERLAY_MODIFF
> inside window_outdated?  Or do you suggest something else?
>
> I'm okay with using BUF_* macros in window_outdated.

There is one more similar thing: if we can enter redisplay_internal
with different current_buffer and selected window's buffer, we can
confuse reconsider_clip_changes, which comment explicitly assumes
that W->buffer and B are the same buffer.

What if we just delay the real redisplay action until current_buffer
and selected window's buffer becomes synchronized, assuming that it
happens in the very near future (when someone finally update current_buffer
with selected window's buffer and then attract redisplay attention with
++windows_or_buffers_changed or similar)?

> So if window_outdated is called not from redisplay_window or its
> subroutines, we cannot assume that current_buffer and the selected
> window's buffer are the same.  Also, for minibuffer windows and
> pseudo-windows, we may need more care, but I'm not sure.

IIUC pseudo-windows are always non-leaf; so, selected_window can't be
a pseudo-window, and pseudo-window can't be passed to redisplay_window.

Attached patch illustrates all from the above.

Dmitry
=== modified file 'src/xdisp.c'
--- src/xdisp.c	2012-11-30 09:23:15 +0000
+++ src/xdisp.c	2012-11-30 15:45:36 +0000
@@ -10906,6 +10906,7 @@
 static int
 window_outdated (struct window *w)
 {
+  eassert (XBUFFER (w->buffer) == current_buffer);
   return (w->last_modified < MODIFF 
 	  || w->last_overlay_modified < OVERLAY_MODIFF);
 }
@@ -12917,6 +12918,8 @@
 static void
 reconsider_clip_changes (struct window *w, struct buffer *b)
 {
+  eassert (XBUFFER (w->buffer) == b);
+
   if (b->clip_changed
 	   && !NILP (w->window_end_valid)
 	   && w->current_matrix->buffer == b
@@ -12924,13 +12927,11 @@
 	   && w->current_matrix->begv == BUF_BEGV (b))
     b->clip_changed = 0;
 
-  /* If display wasn't paused, and W is not a tool bar window, see if
-     point has been moved into or out of a composition.  In that case,
-     we set b->clip_changed to 1 to force updating the screen.  If
-     b->clip_changed has already been set to 1, we can skip this
-     check.  */
-  if (!b->clip_changed
-      && BUFFERP (w->buffer) && !NILP (w->window_end_valid))
+  /* If display wasn't paused, see if point has been moved into or
+     out of a composition.  In that case, we set b->clip_changed
+     to 1 to force updating the screen.  If b->clip_changed has
+     already been set to 1, we can skip this check.  */
+  if (!b->clip_changed && !NILP (w->window_end_valid))
     {
       ptrdiff_t pt;
 
@@ -13079,6 +13080,10 @@
      may need to run Elisp code (via prepare_menu_bars).  */
   ensure_selected_frame (old_frame);
 
+  if (XBUFFER (w->buffer) != current_buffer)
+    /* Out of sync, do nothing.  */
+    goto end_of_redisplay;
+
   pending = 0;
   reconsider_clip_changes (w, current_buffer);
   last_escape_glyph_frame = NULL;
@@ -13136,10 +13141,7 @@
   /* do_pending_window_change could change the selected_window due to
      frame resizing which makes the selected window too small.  */
   if (WINDOWP (selected_window) && (w = XWINDOW (selected_window)) != sw)
-    {
-      sw = w;
-      reconsider_clip_changes (w, current_buffer);
-    }
+    goto retry;
 
   /* Clear frames marked as garbaged.  */
   clear_garbaged_frames ();