Subject: Re: bug#12310: crash in remember_mouse_glyph

From: martin rudalics <[email-masked]>
Date: Thu, 30 Aug 2012 10:32:11 +0200

> Indeed.  I've forgotten to describe the symptoms if not running under
> gdb, and they are the same (visible bell while moving the mouse or
> pressing any key, but no reaction otherwise; I had to kill Emacs, or
> it crashed after some time).

Meanwhile could you try the patch I earlier sent to Sam.  I'll attach it.
Basically, it should help to find the bug earlier.

martin

bzr diff
=== modified file 'src/buffer.c'
--- src/buffer.c	2012-08-24 04:37:57 +0000
+++ src/buffer.c	2012-08-25 13:16:19 +0000
@@ -1351,7 +1351,7 @@
 A non-nil FLAG means mark the buffer modified.  */)
   (Lisp_Object flag)
 {
-  Lisp_Object fn, buffer, window;
+  Lisp_Object fn, buffer;
 
 #ifdef CLASH_DETECTION
   /* If buffer becoming modified, lock the file.
@@ -1401,8 +1401,7 @@
      buffers without "modifying" buffers, or redisplay should be
      smarter about updating the `*' in mode lines.  --gerd  */
   XSETBUFFER (buffer, current_buffer);
-  window = Fget_buffer_window (buffer, Qt);
-  if (WINDOWP (window))
+  if (!NILP (Fget_buffer_window (buffer, Qt)))
     {
       ++update_mode_lines;
       current_buffer->prevent_redisplay_optimizations_p = 1;
@@ -3195,7 +3194,7 @@
 	      Lisp_Object window;
 
 	      window = Foverlay_get (overlay, Qwindow);
-	      if (WINDOWP (window) && XWINDOW (window) != w)
+	      if (WINDOW_LIVE_P (window) && XWINDOW (window) != w)
 		continue;
 	    }
 
@@ -3337,7 +3336,7 @@
       if (endpos != pos && startpos != pos)
 	continue;
       window = Foverlay_get (overlay, Qwindow);
-      if (WINDOWP (window) && XWINDOW (window) != w)
+      if (WINDOW_LIVE_P (window) && XWINDOW (window) != w)
 	continue;
       if (startpos == pos
 	  && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))
@@ -3365,7 +3364,7 @@
       if (endpos != pos && startpos != pos)
 	continue;
       window = Foverlay_get (overlay, Qwindow);
-      if (WINDOWP (window) && XWINDOW (window) != w)
+      if (WINDOW_LIVE_P (window) && XWINDOW (window) != w)
 	continue;
       if (startpos == pos
 	  && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)))

=== modified file 'src/editfns.c'
--- src/editfns.c	2012-08-21 23:39:56 +0000
+++ src/editfns.c	2012-08-25 12:34:37 +0000
@@ -360,7 +360,7 @@
 
   if (NILP (object))
     XSETBUFFER (object, current_buffer);
-  else if (WINDOWP (object))
+  else if (WINDOW_LIVE_P (object))
     object = XWINDOW (object)->buffer;
 
   if (!BUFFERP (object))

=== modified file 'src/frame.c'
--- src/frame.c	2012-08-22 16:05:04 +0000
+++ src/frame.c	2012-08-25 13:14:31 +0000
@@ -951,7 +951,7 @@
 		    || FRAME_ICONIFIED_P (XFRAME (f)))
 		  return f;
 	      }
-	    else if (WINDOWP (minibuf))
+	    else if (WINDOW_LIVE_P (minibuf))
 	      {
 		if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
 		    || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
@@ -1010,7 +1010,7 @@
 	      if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
 		prev = f;
 	    }
-	  else if (WINDOWP (minibuf))
+	  else if (WINDOW_LIVE_P (minibuf))
 	    {
 	      if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
 		  || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
@@ -2150,7 +2150,7 @@
 	set_term_frame_name (f, val);
     }
 
-  if (EQ (prop, Qminibuffer) && WINDOWP (val))
+  if (EQ (prop, Qminibuffer) && WINDOW_LIVE_P (val))
     {
       if (! MINI_WINDOW_P (XWINDOW (val)))
 	error ("Surrogate minibuffer windows must be minibuffer windows");

=== modified file 'src/keyboard.c'
--- src/keyboard.c	2012-08-23 08:33:56 +0000
+++ src/keyboard.c	2012-08-25 12:34:33 +0000
@@ -3521,7 +3521,7 @@
   frame = event->frame_or_window;
   if (CONSP (frame))
     frame = XCAR (frame);
-  else if (WINDOWP (frame))
+  else if (WINDOW_LIVE_P (frame))
     frame = WINDOW_FRAME (XWINDOW (frame));
 
   /* There are still some events that don't set this field.
@@ -3738,7 +3738,7 @@
   event.kind = HELP_EVENT;
   event.frame_or_window = frame;
   event.arg = object;
-  event.x = WINDOWP (window) ? window : frame;
+  event.x = WINDOW_LIVE_P (window) ? window : frame;
   event.y = help;
   event.code = pos;
   kbd_buffer_store_event (&event);
@@ -4064,7 +4064,7 @@
 	  clear_event (event);
 
 	  kbd_fetch_ptr = event + 1;
-	  if (!WINDOWP (window))
+	  if (!WINDOW_LIVE_P (window))
 	    window = Qnil;
 	  obj = Fcons (Qhelp_echo,
 		       list5 (frame, help, window, object, position));
@@ -4109,7 +4109,7 @@
 	  frame = event->frame_or_window;
 	  if (CONSP (frame))
 	    frame = XCAR (frame);
-	  else if (WINDOWP (frame))
+	  else if (WINDOW_LIVE_P (frame))
 	    frame = WINDOW_FRAME (XWINDOW (frame));
 
 	  focus = FRAME_FOCUS_FRAME (XFRAME (frame));
@@ -5192,7 +5192,7 @@
     ? window_from_coordinates (f, XINT (x), XINT (y), &part, 0)
     : Qnil;
 
-  if (WINDOWP (window))
+  if (WINDOW_LIVE_P (window))
     {
       /* It's a click in window WINDOW at frame coordinates (X,Y)  */
       struct window *w = XWINDOW (window);
@@ -5621,7 +5621,7 @@
 	  struct frame *f;
 	  int fuzz;
 
-	  if (WINDOWP (event->frame_or_window))
+	  if (WINDOW_LIVE_P (event->frame_or_window))
 	    f = XFRAME (XWINDOW (event->frame_or_window)->frame);
 	  else if (FRAMEP (event->frame_or_window))
 	    f = XFRAME (event->frame_or_window);
@@ -5789,7 +5789,7 @@
 	  int symbol_num;
 	  int is_double;
 
-	  if (WINDOWP (event->frame_or_window))
+	  if (WINDOW_LIVE_P (event->frame_or_window))
 	    fr = XFRAME (XWINDOW (event->frame_or_window)->frame);
 	  else if (FRAMEP (event->frame_or_window))
 	    fr = XFRAME (event->frame_or_window);
@@ -9555,7 +9555,7 @@
 		     read using the keymaps in the buffer clicked on,
 		     not the current buffer.  If we're at the
 		     beginning of a key sequence, switch buffers.  */
-		  if (WINDOWP (window)
+		  if (WINDOW_LIVE_P (window)
 		      && BUFFERP (XWINDOW (window)->buffer)
 		      && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
 		    {
@@ -11249,7 +11249,7 @@
   if (NILP (frame_or_window))
     frame_or_window = selected_window;
 
-  if (WINDOWP (frame_or_window))
+  if (WINDOW_LIVE_P (frame_or_window))
     {
       struct window *w = decode_live_window (frame_or_window);

=== modified file 'src/keymap.c'
--- src/keymap.c	2012-08-18 06:06:39 +0000
+++ src/keymap.c	2012-08-25 12:41:07 +0000
@@ -1559,7 +1559,7 @@
 
       window = POSN_WINDOW (position);
 
-      if (WINDOWP (window)
+      if (WINDOW_LIVE_P (window)
 	  && BUFFERP (XWINDOW (window)->buffer)
 	  && XBUFFER (XWINDOW (window)->buffer) != current_buffer)
 	{

=== modified file 'src/textprop.c'
--- src/textprop.c	2012-08-17 21:12:11 +0000
+++ src/textprop.c	2012-08-25 13:05:53 +0000
@@ -584,7 +584,7 @@
   if (NILP (object))
     XSETBUFFER (object, current_buffer);
 
-  if (WINDOWP (object))
+  if (WINDOW_LIVE_P (object))
     {
       w = XWINDOW (object);
       object = w->buffer;

=== modified file 'src/w32inevt.c'
--- src/w32inevt.c	2012-07-30 17:07:33 +0000
+++ src/w32inevt.c	2012-08-25 13:06:20 +0000
@@ -650,7 +650,7 @@
 		 selected now, and the last mouse movement event was
 		 not in it.  A minibuffer window will be selected iff
 		 it is active.  */
-	      if (WINDOWP (mouse_window)
+	      if (WINDOW_LIVE_P (mouse_window)
 		  && !EQ (mouse_window, last_mouse_window)
 		  && !EQ (mouse_window, selected_window))
 		{

=== modified file 'src/w32term.c'
--- src/w32term.c	2012-08-18 01:42:52 +0000
+++ src/w32term.c	2012-08-25 13:10:02 +0000
@@ -3927,7 +3927,7 @@
 w32_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg,
 			     struct input_event *emacs_event)
 {
-  if (! WINDOWP (bar->window))
+  if (! WINDOW_LIVE_P (bar->window))
     abort ();
 
   emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
@@ -4420,7 +4420,7 @@
 		     selected now and last mouse movement event was
 		     not in it.  Minibuffer window will be selected
 		     only when it is active.  */
-		  if (WINDOWP (window)
+		  if (WINDOW_LIVE_P (window)
 		      && !EQ (window, last_window)
 		      && !EQ (window, selected_window)
 		      /* For click-to-focus window managers

=== modified file 'src/window.c'
--- src/window.c	2012-08-21 09:27:07 +0000
+++ src/window.c	2012-08-25 12:52:42 +0000
@@ -1969,7 +1969,7 @@
      So don't clobber point in that buffer.  */
   if (! EQ (buf, XWINDOW (selected_window)->buffer)
       /* This line helps to fix Horsley's testbug.el bug.  */
-      && !(WINDOWP (BVAR (b, last_selected_window))
+      && !(WINDOW_LIVE_P (BVAR (b, last_selected_window))
 	   && w != XWINDOW (BVAR (b, last_selected_window))
 	   && EQ (buf, XWINDOW (BVAR (b, last_selected_window))->buffer)))
     temp_set_point_both (b,
@@ -1980,7 +1980,7 @@
 					 marker_byte_position (w->pointm),
 					 BUF_ZV_BYTE (b)));
 
-  if (WINDOWP (BVAR (b, last_selected_window))
+  if (WINDOW_LIVE_P (BVAR (b, last_selected_window))
       && w == XWINDOW (BVAR (b, last_selected_window)))
     bset_last_selected_window (b, Qnil);
 }
@@ -2205,7 +2205,7 @@
     candidate_p = 0;
   else if (MINI_WINDOW_P (w)
            && (EQ (minibuf, Qlambda)
-	       || (WINDOWP (minibuf) && !EQ (minibuf, window))))
+	       || (WINDOW_LIVE_P (minibuf) && !EQ (minibuf, window))))
     {
       /* If MINIBUF is `lambda' don't consider any mini-windows.
          If it is a window, consider only that one.  */
@@ -2215,7 +2215,7 @@
     candidate_p = 1;
   else if (NILP (all_frames))
     {
-      eassert (WINDOWP (owindow));
+      eassert (WINDOW_LIVE_P (owindow));
       candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
     }
   else if (EQ (all_frames, Qvisible))
@@ -2244,7 +2244,7 @@
 	&& (FRAME_TERMINAL (XFRAME (w->frame))
 	    == FRAME_TERMINAL (XFRAME (selected_frame)));
     }
-  else if (WINDOWP (all_frames))
+  else if (WINDOW_LIVE_P (all_frames))
     candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
 		   || EQ (XWINDOW (all_frames)->frame, w->frame)
 		   || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
@@ -2348,7 +2348,7 @@
 	{
 	  if (EQ (XCAR (list), window))
 	    {
-	      if (WINDOWP (candidate))
+	      if (WINDOW_LIVE_P (candidate))
 		break;
 	    }
 	  else if (candidate_window_p (XCAR (list), window, minibuf,
@@ -2356,7 +2356,7 @@
 	    candidate = XCAR (list);
 	}
 
-      if (WINDOWP (candidate))
+      if (WINDOW_LIVE_P (candidate))
 	window = candidate;
     }
 
@@ -2580,7 +2580,7 @@
      or Qt otherwise.  */
 
   /* Pick a window to start with.  */
-  if (WINDOWP (obj))
+  if (WINDOW_LIVE_P (obj))
     window = obj;
   else if (f)
     window = FRAME_SELECTED_WINDOW (f);
@@ -3321,7 +3321,7 @@
       return Qt;
     }
 
-  if (WINDOWP (object))
+  if (WINDOW_LIVE_P (object))
     {
       struct window *w = XWINDOW (object);
       mark_window_display_accurate (object, 0);
@@ -5562,7 +5562,7 @@
 	   the current-selected-window.  So we have to be careful which
 	   point of the current-buffer we copy into old_point.  */
 	if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer)
-	    && WINDOWP (selected_window)
+	    && WINDOW_LIVE_P (selected_window)
 	    && EQ (XWINDOW (selected_window)->buffer, new_current_buffer)
 	    && !EQ (selected_window, data->current_window))
 	  old_point = XMARKER (XWINDOW (data->current_window)->pointm)->charpos;
@@ -6495,7 +6495,7 @@
 		void *user_data)
 {
   /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil.  */
-  if (WINDOWP (FRAME_ROOT_WINDOW (f)))
+  if (WINDOW_VALID_P (FRAME_ROOT_WINDOW (f)))
     foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
 }
 
@@ -6534,7 +6534,7 @@
 freeze_window_start (struct window *w, void *freeze_p)
 {
   if (MINI_WINDOW_P (w)
-      || (WINDOWP (selected_window) /* Can be nil in corner cases.  */
+      || (WINDOW_LIVE_P (selected_window) /* Can be nil in corner cases.  */
          && (w == XWINDOW (selected_window)
              || (MINI_WINDOW_P (XWINDOW (selected_window))
                  && ! NILP (Vminibuf_scroll_window)

=== modified file 'src/xdisp.c'
--- src/xdisp.c	2012-08-21 23:39:56 +0000
+++ src/xdisp.c	2012-08-25 13:16:16 +0000
@@ -2714,7 +2714,7 @@
 	  /* Or show the region if we are in the mini-buffer and W is
 	     the window the mini-buffer refers to.  */
 	  || (MINI_WINDOW_P (XWINDOW (selected_window))
-	      && WINDOWP (minibuf_selected_window)
+	      && WINDOW_LIVE_P (minibuf_selected_window)
 	      && w == XWINDOW (minibuf_selected_window))))
     {
       ptrdiff_t markpos = marker_position (BVAR (current_buffer, mark));
@@ -10082,7 +10082,7 @@
   Vdeactivate_mark = AREF (vector, 1);
   windows_or_buffers_changed = XFASTINT (AREF (vector, 2));
 
-  if (WINDOWP (AREF (vector, 3)))
+  if (WINDOW_LIVE_P (AREF (vector, 3)))
     {
       struct window *w;
       Lisp_Object buffer, charpos, bytepos;
@@ -10251,7 +10251,7 @@
 resize_echo_area_exactly (void)
 {
   if (BUFFERP (echo_area_buffer[0])
-      && WINDOWP (echo_area_window))
+      && WINDOW_LIVE_P (echo_area_window))
     {
       struct window *w = XWINDOW (echo_area_window);
       int resized_p;
@@ -13057,7 +13057,8 @@
 
   /* 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)
+  if (WINDOW_LIVE_P (selected_window)
+      && (w = XWINDOW (selected_window)) != sw)
     {
       sw = w;
       reconsider_clip_changes (w, current_buffer);
@@ -13336,7 +13337,7 @@
 	    {
 	      do_pending_window_change (1);
 	      /* If selected_window changed, redisplay again.  */
-	      if (WINDOWP (selected_window)
+	      if (WINDOW_LIVE_P (selected_window)
 		  && (w = XWINDOW (selected_window)) != sw)
 		goto retry;
 
@@ -13647,7 +13648,8 @@
   /* If we just did a pending size change, or have additional
      visible frames, or selected_window changed, redisplay again.  */
   if ((windows_or_buffers_changed && !pending)
-      || (WINDOWP (selected_window) && (w = XWINDOW (selected_window)) != sw))
+      || (WINDOW_LIVE_P (selected_window)
+	  && (w = XWINDOW (selected_window)) != sw))
     goto retry;
 
   /* Clear the face and image caches.
@@ -26358,7 +26360,7 @@
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
 
   /* Quickly resolve the easy cases.  */
-  if (!(WINDOWP (hlinfo->mouse_face_window)
+  if (!(WINDOW_LIVE_P (hlinfo->mouse_face_window)
 	&& XWINDOW (hlinfo->mouse_face_window) == w))
     return 0;
   if (vpos < hlinfo->mouse_face_beg_row
@@ -27660,7 +27662,7 @@
     clear_mouse_face (hlinfo);
 
   /* Not on a window -> return.  */
-  if (!WINDOWP (window))
+  if (!WINDOW_LIVE_P (window))
     return;
 
   /* Reset help_echo_string. It will get recomputed below.  */

=== modified file 'src/xfaces.c'
--- src/xfaces.c	2012-08-21 10:21:04 +0000
+++ src/xfaces.c	2012-08-25 13:09:58 +0000
@@ -4350,7 +4350,7 @@
 	 matrices as invalid because they will reference faces freed
 	 above.  This function is also called when a frame is
 	 destroyed.  In this case, the root window of F is nil.  */
-      if (WINDOWP (f->root_window))
+      if (WINDOW_VALID_P (f->root_window))
 	{
 	  clear_current_matrices (f);
 	  ++windows_or_buffers_changed;

=== modified file 'src/xterm.c'
--- src/xterm.c	2012-08-18 01:42:52 +0000
+++ src/xterm.c	2012-08-25 13:09:51 +0000
@@ -4235,7 +4235,7 @@
 
   if (scroll_bar_p
       && strcmp (action_name, end_action) == 0
-      && WINDOWP (window_being_scrolled))
+      && WINDOW_LIVE_P (window_being_scrolled))
     {
       struct window *w;
 
@@ -4512,7 +4512,7 @@
 {
   struct scroll_bar *bar = (struct scroll_bar *) user_data;
   bar->dragging = Qnil;
-  if (WINDOWP (window_being_scrolled))
+  if (WINDOW_LIVE_P (window_being_scrolled))
     {
       x_send_scroll_bar_event (window_being_scrolled,
                                scroll_bar_end_scroll, 0, 0);
@@ -5557,7 +5557,7 @@
 static void
 x_scroll_bar_handle_click (struct scroll_bar *bar, XEvent *event, struct input_event *emacs_event)
 {
-  if (! WINDOWP (bar->window))
+  if (! WINDOW_LIVE_P (bar->window))
     abort ();
 
   emacs_event->kind = SCROLL_BAR_CLICK_EVENT;
@@ -6782,7 +6782,7 @@
                 /* Window will be selected only when it is not selected now and
                    last mouse movement event was not in it.  Minibuffer window
                    will be selected only when it is active.  */
-                if (WINDOWP (window)
+                if (WINDOW_LIVE_P (window)
                     && !EQ (window, last_window)
 		    && !EQ (window, selected_window)
 		    /* For click-to-focus window managers