aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-05-12 13:23:33 -0700
committerPaul Eggert2011-05-12 13:23:33 -0700
commit08dc5ae68e9c699410256ca9052bd09f336ac87f (patch)
tree6572186aea70cb9f3f736743271c4d0b500650b6 /src
parent86db42d22397effbb6e9edc5ae11d806847f0d3e (diff)
downloademacs-08dc5ae68e9c699410256ca9052bd09f336ac87f.tar.gz
emacs-08dc5ae68e9c699410256ca9052bd09f336ac87f.zip
Be more systematic about user-interface timestamps.
Before, the code sometimes used 'Time', sometimes 'unsigned long', and sometimes 'EMACS_UINT', to represent these timestamps. This change causes it to use 'Time' uniformly, as that's what X uses. This makes the code easier to follow, and makes it easier to catch integer overflow bugs such as Bug#8664. * frame.c (Fmouse_position, Fmouse_pixel_position): Use Time, not unsigned long, for user-interface timestamps. * keyboard.c (last_event_timestamp, kbd_buffer_get_event): Likewise. (button_down_time, make_lispy_position, make_lispy_movement): Likewise. * keyboard.h (last_event_timestamp): Likewise. * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise. * menu.h (xmenu_show): Likewise. * term.c (term_mouse_position): Likewise. * termhooks.h (struct input_event.timestamp): Likewise. (struct terminal.mouse_position_hook): Likewise. * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise. * xterm.c (XTmouse_position, x_scroll_bar_report_motion): Likewise. * systime.h (Time): New decl. Pull it in from <X11/X.h> if HAVE_X_WINDOWS, otherwise define it as unsigned long, which is what it was before. * menu.h, termhooks.h: Include "systime.h", for Time.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog23
-rw-r--r--src/frame.c4
-rw-r--r--src/keyboard.c10
-rw-r--r--src/keyboard.h4
-rw-r--r--src/menu.c4
-rw-r--r--src/menu.h5
-rw-r--r--src/systime.h6
-rw-r--r--src/term.c2
-rw-r--r--src/termhooks.h6
-rw-r--r--src/xmenu.c13
-rw-r--r--src/xterm.c6
11 files changed, 58 insertions, 25 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b2b19b6c940..a772106c521 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,28 @@
12011-05-12 Paul Eggert <eggert@cs.ucla.edu> 12011-05-12 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Be more systematic about user-interface timestamps.
4 Before, the code sometimes used 'Time', sometimes 'unsigned long',
5 and sometimes 'EMACS_UINT', to represent these timestamps. This
6 change causes it to use 'Time' uniformly, as that's what X uses.
7 This makes the code easier to follow, and makes it easier to catch
8 integer overflow bugs such as Bug#8664.
9 * frame.c (Fmouse_position, Fmouse_pixel_position):
10 Use Time, not unsigned long, for user-interface timestamps.
11 * keyboard.c (last_event_timestamp, kbd_buffer_get_event): Likewise.
12 (button_down_time, make_lispy_position, make_lispy_movement): Likewise.
13 * keyboard.h (last_event_timestamp): Likewise.
14 * menu.c (Fx_popup_menu) [!HAVE_X_WINDOWS]: Likewise.
15 * menu.h (xmenu_show): Likewise.
16 * term.c (term_mouse_position): Likewise.
17 * termhooks.h (struct input_event.timestamp): Likewise.
18 (struct terminal.mouse_position_hook): Likewise.
19 * xmenu.c (create_and_show_popup_menu, xmenu_show): Likewise.
20 * xterm.c (XTmouse_position, x_scroll_bar_report_motion): Likewise.
21 * systime.h (Time): New decl. Pull it in from <X11/X.h> if
22 HAVE_X_WINDOWS, otherwise define it as unsigned long, which is
23 what it was before.
24 * menu.h, termhooks.h: Include "systime.h", for Time.
25
3 * keyboard.c (make_lispy_event): Fix problem in integer overflow. 26 * keyboard.c (make_lispy_event): Fix problem in integer overflow.
4 Don't assume that the difference between two unsigned long values 27 Don't assume that the difference between two unsigned long values
5 can fit into an integer. At this point, we know button_down_time 28 can fit into an integer. At this point, we know button_down_time
diff --git a/src/frame.c b/src/frame.c
index b106c568e48..ce92a83b86c 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1631,7 +1631,7 @@ and returns whatever that function returns. */)
1631 enum scroll_bar_part party_dummy; 1631 enum scroll_bar_part party_dummy;
1632 Lisp_Object x, y, retval; 1632 Lisp_Object x, y, retval;
1633 int col, row; 1633 int col, row;
1634 unsigned long long_dummy; 1634 Time long_dummy;
1635 struct gcpro gcpro1; 1635 struct gcpro gcpro1;
1636 1636
1637 f = SELECTED_FRAME (); 1637 f = SELECTED_FRAME ();
@@ -1676,7 +1676,7 @@ and nil for X and Y. */)
1676 Lisp_Object lispy_dummy; 1676 Lisp_Object lispy_dummy;
1677 enum scroll_bar_part party_dummy; 1677 enum scroll_bar_part party_dummy;
1678 Lisp_Object x, y; 1678 Lisp_Object x, y;
1679 unsigned long long_dummy; 1679 Time long_dummy;
1680 1680
1681 f = SELECTED_FRAME (); 1681 f = SELECTED_FRAME ();
1682 x = y = Qnil; 1682 x = y = Qnil;
diff --git a/src/keyboard.c b/src/keyboard.c
index 287996ffba9..c471a91ebfb 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -238,7 +238,7 @@ Lisp_Object internal_last_event_frame;
238 238
239/* The timestamp of the last input event we received from the X server. 239/* The timestamp of the last input event we received from the X server.
240 X Windows wants this for selection ownership. */ 240 X Windows wants this for selection ownership. */
241unsigned long last_event_timestamp; 241Time last_event_timestamp;
242 242
243static Lisp_Object Qx_set_selection, Qhandle_switch_frame; 243static Lisp_Object Qx_set_selection, Qhandle_switch_frame;
244Lisp_Object QPRIMARY; 244Lisp_Object QPRIMARY;
@@ -4085,7 +4085,7 @@ kbd_buffer_get_event (KBOARD **kbp,
4085 Lisp_Object bar_window; 4085 Lisp_Object bar_window;
4086 enum scroll_bar_part part; 4086 enum scroll_bar_part part;
4087 Lisp_Object x, y; 4087 Lisp_Object x, y;
4088 unsigned long t; 4088 Time t;
4089 4089
4090 *kbp = current_kboard; 4090 *kbp = current_kboard;
4091 /* Note that this uses F to determine which terminal to look at. 4091 /* Note that this uses F to determine which terminal to look at.
@@ -5088,7 +5088,7 @@ static Lisp_Object button_down_location;
5088static int last_mouse_button; 5088static int last_mouse_button;
5089static int last_mouse_x; 5089static int last_mouse_x;
5090static int last_mouse_y; 5090static int last_mouse_y;
5091static unsigned long button_down_time; 5091static Time button_down_time;
5092 5092
5093/* The number of clicks in this multiple-click. */ 5093/* The number of clicks in this multiple-click. */
5094 5094
@@ -5099,7 +5099,7 @@ static int double_click_count;
5099 5099
5100static Lisp_Object 5100static Lisp_Object
5101make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y, 5101make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
5102 unsigned long t) 5102 Time t)
5103{ 5103{
5104 enum window_part part; 5104 enum window_part part;
5105 Lisp_Object posn = Qnil; 5105 Lisp_Object posn = Qnil;
@@ -5987,7 +5987,7 @@ make_lispy_event (struct input_event *event)
5987 5987
5988static Lisp_Object 5988static Lisp_Object
5989make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part, 5989make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part,
5990 Lisp_Object x, Lisp_Object y, unsigned long t) 5990 Lisp_Object x, Lisp_Object y, Time t)
5991{ 5991{
5992 /* Is it a scroll bar movement? */ 5992 /* Is it a scroll bar movement? */
5993 if (frame && ! NILP (bar_window)) 5993 if (frame && ! NILP (bar_window))
diff --git a/src/keyboard.h b/src/keyboard.h
index 1f5cbd23639..802c99edb5e 100644
--- a/src/keyboard.h
+++ b/src/keyboard.h
@@ -16,7 +16,7 @@ GNU General Public License for more details.
16You should have received a copy of the GNU General Public License 16You should have received a copy of the GNU General Public License
17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18 18
19#include "systime.h" /* for EMACS_TIME */ 19#include "systime.h" /* for EMACS_TIME, Time */
20#include "coding.h" /* for ENCODE_UTF_8 and ENCODE_SYSTEM */ 20#include "coding.h" /* for ENCODE_UTF_8 and ENCODE_SYSTEM */
21 21
22/* Lisp fields in struct keyboard are hidden from most code and accessed 22/* Lisp fields in struct keyboard are hidden from most code and accessed
@@ -459,7 +459,7 @@ extern Lisp_Object Qevent_symbol_element_mask;
459 459
460/* The timestamp of the last input event we received from the X server. 460/* The timestamp of the last input event we received from the X server.
461 X Windows wants this for selection ownership. */ 461 X Windows wants this for selection ownership. */
462extern unsigned long last_event_timestamp; 462extern Time last_event_timestamp;
463 463
464extern int quit_char; 464extern int quit_char;
465 465
diff --git a/src/menu.c b/src/menu.c
index 705100381d5..d2486439fd0 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -1147,13 +1147,13 @@ no quit occurs and `x-popup-menu' returns nil. */)
1147#else /* not HAVE_X_WINDOWS */ 1147#else /* not HAVE_X_WINDOWS */
1148 Lisp_Object bar_window; 1148 Lisp_Object bar_window;
1149 enum scroll_bar_part part; 1149 enum scroll_bar_part part;
1150 unsigned long time; 1150 Time time;
1151 void (*mouse_position_hook) (struct frame **, int, 1151 void (*mouse_position_hook) (struct frame **, int,
1152 Lisp_Object *, 1152 Lisp_Object *,
1153 enum scroll_bar_part *, 1153 enum scroll_bar_part *,
1154 Lisp_Object *, 1154 Lisp_Object *,
1155 Lisp_Object *, 1155 Lisp_Object *,
1156 unsigned long *) = 1156 Time *) =
1157 FRAME_TERMINAL (new_f)->mouse_position_hook; 1157 FRAME_TERMINAL (new_f)->mouse_position_hook;
1158 1158
1159 if (mouse_position_hook) 1159 if (mouse_position_hook)
diff --git a/src/menu.h b/src/menu.h
index c3978dae8eb..451401b42d5 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -19,6 +19,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19#ifndef MENU_H 19#ifndef MENU_H
20#define MENU_H 20#define MENU_H
21 21
22#include "systime.h" /* for Time */
23
22extern void x_set_menu_bar_lines (struct frame *f, 24extern void x_set_menu_bar_lines (struct frame *f,
23 Lisp_Object value, 25 Lisp_Object value,
24 Lisp_Object oldval); 26 Lisp_Object oldval);
@@ -48,6 +50,5 @@ extern Lisp_Object w32_menu_show (FRAME_PTR, int, int, int, int,
48extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, int, int, 50extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, int, int,
49 Lisp_Object, const char **); 51 Lisp_Object, const char **);
50extern Lisp_Object xmenu_show (FRAME_PTR, int, int, int, int, 52extern Lisp_Object xmenu_show (FRAME_PTR, int, int, int, int,
51 Lisp_Object, const char **, EMACS_UINT); 53 Lisp_Object, const char **, Time);
52#endif /* MENU_H */ 54#endif /* MENU_H */
53
diff --git a/src/systime.h b/src/systime.h
index cb1ea230f7d..db43b26dc5e 100644
--- a/src/systime.h
+++ b/src/systime.h
@@ -30,6 +30,12 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
30#endif 30#endif
31#endif 31#endif
32 32
33#ifdef HAVE_X_WINDOWS
34# include <X11/X.h>
35#else
36typedef unsigned long Time;
37#endif
38
33#ifdef HAVE_TZNAME 39#ifdef HAVE_TZNAME
34#ifndef tzname /* For SGI. */ 40#ifndef tzname /* For SGI. */
35extern char *tzname[]; /* RS6000 and others want it this way. */ 41extern char *tzname[]; /* RS6000 and others want it this way. */
diff --git a/src/term.c b/src/term.c
index c68228cc51a..34320a1ad6d 100644
--- a/src/term.c
+++ b/src/term.c
@@ -2698,7 +2698,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
2698static void 2698static void
2699term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 2699term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
2700 enum scroll_bar_part *part, Lisp_Object *x, 2700 enum scroll_bar_part *part, Lisp_Object *x,
2701 Lisp_Object *y, unsigned long *timeptr) 2701 Lisp_Object *y, Time *timeptr)
2702{ 2702{
2703 struct timeval now; 2703 struct timeval now;
2704 2704
diff --git a/src/termhooks.h b/src/termhooks.h
index 3a49b49aede..34e1364effd 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -20,6 +20,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21/* Miscellanea. */ 21/* Miscellanea. */
22 22
23#include "systime.h" /* for Time */
24
23struct glyph; 25struct glyph;
24struct frame; 26struct frame;
25 27
@@ -233,7 +235,7 @@ struct input_event
233 int modifiers; /* See enum below for interpretation. */ 235 int modifiers; /* See enum below for interpretation. */
234 236
235 Lisp_Object x, y; 237 Lisp_Object x, y;
236 unsigned long timestamp; 238 Time timestamp;
237 239
238 /* This is padding just to put the frame_or_window field 240 /* This is padding just to put the frame_or_window field
239 past the size of struct selection_input_event. */ 241 past the size of struct selection_input_event. */
@@ -463,7 +465,7 @@ struct terminal
463 enum scroll_bar_part *part, 465 enum scroll_bar_part *part,
464 Lisp_Object *x, 466 Lisp_Object *x,
465 Lisp_Object *y, 467 Lisp_Object *y,
466 unsigned long *); 468 Time *);
467 469
468 /* The window system handling code should set this if the mouse has 470 /* The window system handling code should set this if the mouse has
469 moved since the last call to the mouse_position_hook. Calling that 471 moved since the last call to the mouse_position_hook. Calling that
diff --git a/src/xmenu.c b/src/xmenu.c
index ccb60d2dcbb..7d7515a8f25 100644
--- a/src/xmenu.c
+++ b/src/xmenu.c
@@ -240,7 +240,7 @@ for instance using the window manager, then this produces a quit and
240 FRAME_PTR new_f = SELECTED_FRAME (); 240 FRAME_PTR new_f = SELECTED_FRAME ();
241 Lisp_Object bar_window; 241 Lisp_Object bar_window;
242 enum scroll_bar_part part; 242 enum scroll_bar_part part;
243 unsigned long time; 243 Time time;
244 Lisp_Object x, y; 244 Lisp_Object x, y;
245 245
246 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time); 246 (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
@@ -1420,7 +1420,8 @@ pop_down_menu (Lisp_Object arg)
1420 menu pops down. 1420 menu pops down.
1421 menu_item_selection will be set to the selection. */ 1421 menu_item_selection will be set to the selection. */
1422static void 1422static void
1423create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, int for_click, EMACS_UINT timestamp) 1423create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
1424 int for_click, Time timestamp)
1424{ 1425{
1425 int i; 1426 int i;
1426 GtkWidget *menu; 1427 GtkWidget *menu;
@@ -1464,7 +1465,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, i
1464 gtk_widget_show_all (menu); 1465 gtk_widget_show_all (menu);
1465 1466
1466 gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i, 1467 gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i,
1467 timestamp > 0 ? timestamp : gtk_get_current_event_time()); 1468 timestamp ? timestamp : gtk_get_current_event_time ());
1468 1469
1469 record_unwind_protect (pop_down_menu, make_save_value (menu, 0)); 1470 record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
1470 1471
@@ -1524,7 +1525,7 @@ pop_down_menu (Lisp_Object arg)
1524 menu_item_selection will be set to the selection. */ 1525 menu_item_selection will be set to the selection. */
1525static void 1526static void
1526create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, 1527create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
1527 int x, int y, int for_click, EMACS_UINT timestamp) 1528 int x, int y, int for_click, Time timestamp)
1528{ 1529{
1529 int i; 1530 int i;
1530 Arg av[2]; 1531 Arg av[2];
@@ -1598,7 +1599,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
1598 1599
1599Lisp_Object 1600Lisp_Object
1600xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, 1601xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
1601 Lisp_Object title, const char **error_name, EMACS_UINT timestamp) 1602 Lisp_Object title, const char **error_name, Time timestamp)
1602{ 1603{
1603 int i; 1604 int i;
1604 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0; 1605 widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
@@ -2241,7 +2242,7 @@ pop_down_menu (Lisp_Object arg)
2241 2242
2242Lisp_Object 2243Lisp_Object
2243xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps, 2244xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
2244 Lisp_Object title, const char **error_name, EMACS_UINT timestamp) 2245 Lisp_Object title, const char **error_name, Time timestamp)
2245{ 2246{
2246 Window root; 2247 Window root;
2247 XMenu *menu; 2248 XMenu *menu;
diff --git a/src/xterm.c b/src/xterm.c
index f5886ab9628..71dc6f16858 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -342,7 +342,7 @@ static struct scroll_bar *x_window_to_scroll_bar (Display *, Window);
342static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *, 342static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
343 enum scroll_bar_part *, 343 enum scroll_bar_part *,
344 Lisp_Object *, Lisp_Object *, 344 Lisp_Object *, Lisp_Object *,
345 unsigned long *); 345 Time *);
346static void x_handle_net_wm_state (struct frame *, XPropertyEvent *); 346static void x_handle_net_wm_state (struct frame *, XPropertyEvent *);
347static void x_check_fullscreen (struct frame *); 347static void x_check_fullscreen (struct frame *);
348static void x_check_expected_move (struct frame *, int, int); 348static void x_check_expected_move (struct frame *, int, int);
@@ -3799,7 +3799,7 @@ redo_mouse_highlight (void)
3799static void 3799static void
3800XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window, 3800XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
3801 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y, 3801 enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
3802 long unsigned int *timestamp) 3802 Time *timestamp)
3803{ 3803{
3804 FRAME_PTR f1; 3804 FRAME_PTR f1;
3805 3805
@@ -5534,7 +5534,7 @@ x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
5534static void 5534static void
5535x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window, 5535x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
5536 enum scroll_bar_part *part, Lisp_Object *x, 5536 enum scroll_bar_part *part, Lisp_Object *x,
5537 Lisp_Object *y, long unsigned int *timestamp) 5537 Lisp_Object *y, Time *timestamp)
5538{ 5538{
5539 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar); 5539 struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
5540 Window w = bar->x_window; 5540 Window w = bar->x_window;