aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2025-01-26 22:15:49 -0800
committerPaul Eggert2025-01-26 23:05:53 -0800
commit2e8ef0910412aef8f9f1beba7c942473ad8602bb (patch)
treeb3afdeef0bb73cac9c1531a2ef28eb8766448dbe
parentff65cc9944dc0b37986d512ee8b9817c6913db36 (diff)
downloademacs-2e8ef0910412aef8f9f1beba7c942473ad8602bb.tar.gz
emacs-2e8ef0910412aef8f9f1beba7c942473ad8602bb.zip
Protect against GCing of last_mouse_window
* 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.
-rw-r--r--src/androidterm.c1
-rw-r--r--src/haikuterm.c1
-rw-r--r--src/msdos.c2
-rw-r--r--src/pgtkterm.c1
-rw-r--r--src/w32inevt.c1
-rw-r--r--src/w32term.c1
-rw-r--r--src/window.c6
-rw-r--r--src/window.h4
-rw-r--r--src/xterm.c3
9 files changed, 10 insertions, 10 deletions
diff --git a/src/androidterm.c b/src/androidterm.c
index 688f254ee23..e0f66652300 100644
--- a/src/androidterm.c
+++ b/src/androidterm.c
@@ -1179,7 +1179,6 @@ handle_one_android_event (struct android_display_info *dpyinfo,
1179 && (f == XFRAME (selected_frame) 1179 && (f == XFRAME (selected_frame)
1180 || !NILP (focus_follows_mouse))) 1180 || !NILP (focus_follows_mouse)))
1181 { 1181 {
1182 static Lisp_Object last_mouse_window;
1183 Lisp_Object window 1182 Lisp_Object window
1184 = window_from_coordinates (f, event->xmotion.x, 1183 = window_from_coordinates (f, event->xmotion.x,
1185 event->xmotion.y, 0, 1184 event->xmotion.y, 0,
diff --git a/src/haikuterm.c b/src/haikuterm.c
index 7f02de2ca15..4a217c9e0e2 100644
--- a/src/haikuterm.c
+++ b/src/haikuterm.c
@@ -3562,7 +3562,6 @@ haiku_read_socket (struct terminal *terminal, struct input_event *hold_quit)
3562 3562
3563 if (!NILP (Vmouse_autoselect_window)) 3563 if (!NILP (Vmouse_autoselect_window))
3564 { 3564 {
3565 static Lisp_Object last_mouse_window;
3566 Lisp_Object window = window_from_coordinates (f, b->x, b->y, 0, 0, 0, 0); 3565 Lisp_Object window = window_from_coordinates (f, b->x, b->y, 0, 0, 0, 0);
3567 3566
3568 if (WINDOWP (window) 3567 if (WINDOWP (window)
diff --git a/src/msdos.c b/src/msdos.c
index 95eb6453040..49403ba72f4 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -2677,8 +2677,6 @@ dos_rawgetc (void)
2677 /* Generate SELECT_WINDOW_EVENTs when needed. */ 2677 /* Generate SELECT_WINDOW_EVENTs when needed. */
2678 if (!NILP (Vmouse_autoselect_window)) 2678 if (!NILP (Vmouse_autoselect_window))
2679 { 2679 {
2680 static Lisp_Object last_mouse_window;
2681
2682 mouse_window = window_from_coordinates 2680 mouse_window = window_from_coordinates
2683 (SELECTED_FRAME (), mouse_last_x, mouse_last_y, 0, 0, 0, 0); 2681 (SELECTED_FRAME (), mouse_last_x, mouse_last_y, 0, 0, 0, 0);
2684 /* A window will be selected only when it is not 2682 /* A window will be selected only when it is not
diff --git a/src/pgtkterm.c b/src/pgtkterm.c
index 2da1006b6f7..0f272bbeac8 100644
--- a/src/pgtkterm.c
+++ b/src/pgtkterm.c
@@ -5938,7 +5938,6 @@ motion_notify_event (GtkWidget *widget, GdkEvent *event,
5938 also when the target window is on another frame. */ 5938 also when the target window is on another frame. */
5939 && (f == XFRAME (selected_frame) || !NILP (focus_follows_mouse))) 5939 && (f == XFRAME (selected_frame) || !NILP (focus_follows_mouse)))
5940 { 5940 {
5941 static Lisp_Object last_mouse_window;
5942 Lisp_Object window = window_from_coordinates 5941 Lisp_Object window = window_from_coordinates
5943 (f, event->motion.x, event->motion.y, 0, false, false, false); 5942 (f, event->motion.x, event->motion.y, 0, false, false, false);
5944 5943
diff --git a/src/w32inevt.c b/src/w32inevt.c
index 1c80f7c6db7..b0e6b5a9286 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -467,7 +467,6 @@ do_mouse_event (MOUSE_EVENT_RECORD *event,
467 struct input_event *emacs_ev) 467 struct input_event *emacs_ev)
468{ 468{
469 static DWORD button_state = 0; 469 static DWORD button_state = 0;
470 static Lisp_Object last_mouse_window;
471 DWORD but_change, mask, flags = event->dwEventFlags; 470 DWORD but_change, mask, flags = event->dwEventFlags;
472 int i; 471 int i;
473 472
diff --git a/src/w32term.c b/src/w32term.c
index cb7bc7e4540..5613ade01ce 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -5444,7 +5444,6 @@ w32_read_socket (struct terminal *terminal,
5444 || (!NILP (focus_follows_mouse) 5444 || (!NILP (focus_follows_mouse)
5445 && !FRAME_NO_ACCEPT_FOCUS (f)))) 5445 && !FRAME_NO_ACCEPT_FOCUS (f))))
5446 { 5446 {
5447 static Lisp_Object last_mouse_window;
5448 Lisp_Object window = window_from_coordinates 5447 Lisp_Object window = window_from_coordinates
5449 (f, LOWORD (msg.msg.lParam), HIWORD (msg.msg.lParam), 0, 0, 0, 0); 5448 (f, LOWORD (msg.msg.lParam), HIWORD (msg.msg.lParam), 0, 0, 0, 0);
5450 5449
diff --git a/src/window.c b/src/window.c
index 0ed1b53d866..330a95a716f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -106,6 +106,9 @@ Lisp_Object minibuf_window;
106 shown as the selected window when the minibuffer is selected. */ 106 shown as the selected window when the minibuffer is selected. */
107Lisp_Object minibuf_selected_window; 107Lisp_Object minibuf_selected_window;
108 108
109/* Non-nil means it is the window containing the last mouse movement. */
110Lisp_Object last_mouse_window;
111
109/* Incremented for each window created. */ 112/* Incremented for each window created. */
110static EMACS_INT sequence_number; 113static EMACS_INT sequence_number;
111 114
@@ -8778,6 +8781,8 @@ init_window_once (void)
8778 8781
8779 minibuf_selected_window = Qnil; 8782 minibuf_selected_window = Qnil;
8780 staticpro (&minibuf_selected_window); 8783 staticpro (&minibuf_selected_window);
8784 last_mouse_window = Qnil;
8785 staticpro (&last_mouse_window);
8781 old_selected_window = Qnil; 8786 old_selected_window = Qnil;
8782 staticpro (&old_selected_window); 8787 staticpro (&old_selected_window);
8783 8788
@@ -8796,6 +8801,7 @@ static void init_window_once_for_pdumper (void)
8796 PDUMPER_RESET_LV (selected_window, Qnil); 8801 PDUMPER_RESET_LV (selected_window, Qnil);
8797 PDUMPER_RESET_LV (Vwindow_list, Qnil); 8802 PDUMPER_RESET_LV (Vwindow_list, Qnil);
8798 PDUMPER_RESET_LV (minibuf_selected_window, Qnil); 8803 PDUMPER_RESET_LV (minibuf_selected_window, Qnil);
8804 PDUMPER_RESET_LV (last_mouse_window, Qnil);
8799 8805
8800 /* Hack: if mode_line_in_non_selected_windows is true (which it may 8806 /* Hack: if mode_line_in_non_selected_windows is true (which it may
8801 be, if we're restoring from a dump) the guts of 8807 be, if we're restoring from a dump) the guts of
diff --git a/src/window.h b/src/window.h
index a48c370b198..2266fc7814c 100644
--- a/src/window.h
+++ b/src/window.h
@@ -1116,6 +1116,10 @@ extern Lisp_Object minibuf_window;
1116 1116
1117extern Lisp_Object minibuf_selected_window; 1117extern Lisp_Object minibuf_selected_window;
1118 1118
1119/* Non-nil means it is the window containing the last mouse movement. */
1120
1121extern Lisp_Object last_mouse_window;
1122
1119extern Lisp_Object make_window (void); 1123extern Lisp_Object make_window (void);
1120extern Lisp_Object window_from_coordinates (struct frame *, int, int, 1124extern Lisp_Object window_from_coordinates (struct frame *, int, int,
1121 enum window_part *, bool, bool, bool); 1125 enum window_part *, bool, bool, bool);
diff --git a/src/xterm.c b/src/xterm.c
index fd61d5df91c..e024b36daf5 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -21291,8 +21291,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
21291 && (f == XFRAME (selected_frame) 21291 && (f == XFRAME (selected_frame)
21292 || !NILP (focus_follows_mouse))) 21292 || !NILP (focus_follows_mouse)))
21293 { 21293 {
21294 static Lisp_Object last_mouse_window;
21295
21296 if (xmotion.window != FRAME_X_WINDOW (f)) 21294 if (xmotion.window != FRAME_X_WINDOW (f))
21297 { 21295 {
21298 x_translate_coordinates (f, xmotion.x_root, xmotion.y_root, 21296 x_translate_coordinates (f, xmotion.x_root, xmotion.y_root,
@@ -23231,7 +23229,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
23231 && (f == XFRAME (selected_frame) 23229 && (f == XFRAME (selected_frame)
23232 || !NILP (focus_follows_mouse))) 23230 || !NILP (focus_follows_mouse)))
23233 { 23231 {
23234 static Lisp_Object last_mouse_window;
23235 Lisp_Object window = window_from_coordinates (f, ev.x, ev.y, 0, false, false, 23232 Lisp_Object window = window_from_coordinates (f, ev.x, ev.y, 0, false, false,
23236 false); 23233 false);
23237 23234