]> git.eshelyaron.com Git - emacs.git/commitdiff
Protect against GCing of last_mouse_window
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 27 Jan 2025 06:15:49 +0000 (22:15 -0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 30 Jan 2025 18:07:08 +0000 (19:07 +0100)
* src/window.c (last_mouse_window): New global var.  All static
instances removed, and all their uses replaced with this global
var.  This fixes a very unlikely bug where last_mouse_window was
GC’ed and a new window created in its place.  It also fixes several
places that assumed NIL_IS_ZERO without static_asserting it.
(init_window_once): Initialize the new var.

(cherry picked from commit 2e8ef0910412aef8f9f1beba7c942473ad8602bb)

src/androidterm.c
src/haikuterm.c
src/msdos.c
src/pgtkterm.c
src/w32inevt.c
src/w32term.c
src/window.c
src/window.h
src/xterm.c

index 688f254ee23962acaf8c2aface6ba466dd199ae3..e0f666523000d3ae519325e73960d6b50ebe1c1a 100644 (file)
@@ -1179,7 +1179,6 @@ handle_one_android_event (struct android_display_info *dpyinfo,
              && (f == XFRAME (selected_frame)
                  || !NILP (focus_follows_mouse)))
            {
-             static Lisp_Object last_mouse_window;
              Lisp_Object window
                = window_from_coordinates (f, event->xmotion.x,
                                           event->xmotion.y, 0,
index 7f02de2ca15e7dad98e91696db54559111a9510e..4a217c9e0e2c9218f32bd860f7ae167b9be68caf 100644 (file)
@@ -3562,7 +3562,6 @@ haiku_read_socket (struct terminal *terminal, struct input_event *hold_quit)
 
                if (!NILP (Vmouse_autoselect_window))
                  {
-                   static Lisp_Object last_mouse_window;
                    Lisp_Object window = window_from_coordinates (f, b->x, b->y, 0, 0, 0, 0);
 
                    if (WINDOWP (window)
index 95eb645304046143103c7ae33c0d400a76d92ac1..49403ba72f41c2e4efae5b8189c2a456460dc819 100644 (file)
@@ -2677,8 +2677,6 @@ dos_rawgetc (void)
          /* Generate SELECT_WINDOW_EVENTs when needed.  */
          if (!NILP (Vmouse_autoselect_window))
            {
-             static Lisp_Object last_mouse_window;
-
              mouse_window = window_from_coordinates
                (SELECTED_FRAME (), mouse_last_x, mouse_last_y, 0, 0, 0, 0);
              /* A window will be selected only when it is not
index 2da1006b6f78966dd9f5cde53493068340bfc6f7..0f272bbeac85498890da4a3184a1c36c3ad94f50 100644 (file)
@@ -5938,7 +5938,6 @@ motion_notify_event (GtkWidget *widget, GdkEvent *event,
             also when the target window is on another frame.  */
          && (f == XFRAME (selected_frame) || !NILP (focus_follows_mouse)))
        {
-         static Lisp_Object last_mouse_window;
          Lisp_Object window = window_from_coordinates
            (f, event->motion.x, event->motion.y, 0, false, false, false);
 
index 1c80f7c6db7c0088c95988d09a67b9e23d0f5ffc..b0e6b5a92864456f4b18e536fbfe51c1abdf9b64 100644 (file)
@@ -467,7 +467,6 @@ do_mouse_event (MOUSE_EVENT_RECORD *event,
                struct input_event *emacs_ev)
 {
   static DWORD button_state = 0;
-  static Lisp_Object last_mouse_window;
   DWORD but_change, mask, flags = event->dwEventFlags;
   int i;
 
index cb7bc7e454007b37f4765e34c7e8575f1b4c56e9..5613ade01cef3f14e2577592913b4b9983e3537c 100644 (file)
@@ -5444,7 +5444,6 @@ w32_read_socket (struct terminal *terminal,
                      || (!NILP (focus_follows_mouse)
                          && !FRAME_NO_ACCEPT_FOCUS (f))))
                {
-                 static Lisp_Object last_mouse_window;
                  Lisp_Object window = window_from_coordinates
                    (f, LOWORD (msg.msg.lParam), HIWORD (msg.msg.lParam), 0, 0, 0, 0);
 
index 0ed1b53d86686f331b5af36d819d2d11fa5a8936..330a95a716f701ef59635fe90e09236b641f6908 100644 (file)
@@ -106,6 +106,9 @@ Lisp_Object minibuf_window;
    shown as the selected window when the minibuffer is selected.  */
 Lisp_Object minibuf_selected_window;
 
+/* Non-nil means it is the window containing the last mouse movement.  */
+Lisp_Object last_mouse_window;
+
 /* Incremented for each window created.  */
 static EMACS_INT sequence_number;
 
@@ -8778,6 +8781,8 @@ init_window_once (void)
 
   minibuf_selected_window = Qnil;
   staticpro (&minibuf_selected_window);
+  last_mouse_window = Qnil;
+  staticpro (&last_mouse_window);
   old_selected_window = Qnil;
   staticpro (&old_selected_window);
 
@@ -8796,6 +8801,7 @@ static void init_window_once_for_pdumper (void)
   PDUMPER_RESET_LV (selected_window, Qnil);
   PDUMPER_RESET_LV (Vwindow_list, Qnil);
   PDUMPER_RESET_LV (minibuf_selected_window, Qnil);
+  PDUMPER_RESET_LV (last_mouse_window, Qnil);
 
   /* Hack: if mode_line_in_non_selected_windows is true (which it may
      be, if we're restoring from a dump) the guts of
index a48c370b1987c4c380cf414fb62ec84bd638da64..2266fc7814c84100db9cae1eafa108cbe015651d 100644 (file)
@@ -1116,6 +1116,10 @@ extern Lisp_Object minibuf_window;
 
 extern Lisp_Object minibuf_selected_window;
 
+/* Non-nil means it is the window containing the last mouse movement.  */
+
+extern Lisp_Object last_mouse_window;
+
 extern Lisp_Object make_window (void);
 extern Lisp_Object window_from_coordinates (struct frame *, int, int,
                                             enum window_part *, bool, bool, bool);
index fd61d5df91c3fbfc3c76ba28cf7d423d2c5d0b85..e024b36daf517641d14f9ea6bb3ae79926da31b4 100644 (file)
@@ -21291,8 +21291,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                && (f == XFRAME (selected_frame)
                    || !NILP (focus_follows_mouse)))
              {
-               static Lisp_Object last_mouse_window;
-
                if (xmotion.window != FRAME_X_WINDOW (f))
                  {
                    x_translate_coordinates (f, xmotion.x_root, xmotion.y_root,
@@ -23231,7 +23229,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                      && (f == XFRAME (selected_frame)
                          || !NILP (focus_follows_mouse)))
                    {
-                     static Lisp_Object last_mouse_window;
                      Lisp_Object window = window_from_coordinates (f, ev.x, ev.y, 0, false, false,
                                                                    false);