]> code.delx.au - gnu-emacs/commitdiff
Be more systematic about user-interface timestamps.
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 May 2011 20:23:33 +0000 (13:23 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 12 May 2011 20:23:33 +0000 (13:23 -0700)
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.

src/ChangeLog
src/frame.c
src/keyboard.c
src/keyboard.h
src/menu.c
src/menu.h
src/systime.h
src/term.c
src/termhooks.h
src/xmenu.c
src/xterm.c

index b2b19b6c940ed43d40614ca056b7edd79c8f5656..a772106c5211bc53a0fe39430e1ee0c7e81bcff0 100644 (file)
@@ -1,5 +1,28 @@
 2011-05-12  Paul Eggert  <eggert@cs.ucla.edu>
 
+       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.
+
        * keyboard.c (make_lispy_event): Fix problem in integer overflow.
        Don't assume that the difference between two unsigned long values
        can fit into an integer.  At this point, we know button_down_time
index b106c568e48f0ef5265a94841f4731de3ee8d42c..ce92a83b86cb71b947288e661de394630b105c00 100644 (file)
@@ -1631,7 +1631,7 @@ and returns whatever that function returns.  */)
   enum scroll_bar_part party_dummy;
   Lisp_Object x, y, retval;
   int col, row;
-  unsigned long long_dummy;
+  Time long_dummy;
   struct gcpro gcpro1;
 
   f = SELECTED_FRAME ();
@@ -1676,7 +1676,7 @@ and nil for X and Y.  */)
   Lisp_Object lispy_dummy;
   enum scroll_bar_part party_dummy;
   Lisp_Object x, y;
-  unsigned long long_dummy;
+  Time long_dummy;
 
   f = SELECTED_FRAME ();
   x = y = Qnil;
index 287996ffba93d4eddcc0fa57b79c3f954688ec8f..c471a91ebfbcdbb43f4325a2ad318a4b73ee0d4f 100644 (file)
@@ -238,7 +238,7 @@ Lisp_Object internal_last_event_frame;
 
 /* The timestamp of the last input event we received from the X server.
    X Windows wants this for selection ownership.  */
-unsigned long last_event_timestamp;
+Time last_event_timestamp;
 
 static Lisp_Object Qx_set_selection, Qhandle_switch_frame;
 Lisp_Object QPRIMARY;
@@ -4085,7 +4085,7 @@ kbd_buffer_get_event (KBOARD **kbp,
       Lisp_Object bar_window;
       enum scroll_bar_part part;
       Lisp_Object x, y;
-      unsigned long t;
+      Time t;
 
       *kbp = current_kboard;
       /* Note that this uses F to determine which terminal to look at.
@@ -5088,7 +5088,7 @@ static Lisp_Object button_down_location;
 static int last_mouse_button;
 static int last_mouse_x;
 static int last_mouse_y;
-static unsigned long button_down_time;
+static Time button_down_time;
 
 /* The number of clicks in this multiple-click. */
 
@@ -5099,7 +5099,7 @@ static int double_click_count;
 
 static Lisp_Object
 make_lispy_position (struct frame *f, Lisp_Object x, Lisp_Object y,
-                    unsigned long t)
+                    Time t)
 {
   enum window_part part;
   Lisp_Object posn = Qnil;
@@ -5987,7 +5987,7 @@ make_lispy_event (struct input_event *event)
 
 static Lisp_Object
 make_lispy_movement (FRAME_PTR frame, Lisp_Object bar_window, enum scroll_bar_part part,
-                    Lisp_Object x, Lisp_Object y, unsigned long t)
+                    Lisp_Object x, Lisp_Object y, Time t)
 {
   /* Is it a scroll bar movement?  */
   if (frame && ! NILP (bar_window))
index 1f5cbd2363995f8c24be6cab785c4633963d7af7..802c99edb5ef073ea6755ac595250d2eca2206f9 100644 (file)
@@ -16,7 +16,7 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#include "systime.h"           /* for EMACS_TIME */
+#include "systime.h"           /* for EMACS_TIME, Time */
 #include "coding.h"             /* for ENCODE_UTF_8 and ENCODE_SYSTEM */
 
 /* Lisp fields in struct keyboard are hidden from most code and accessed
@@ -459,7 +459,7 @@ extern Lisp_Object Qevent_symbol_element_mask;
 
 /* The timestamp of the last input event we received from the X server.
    X Windows wants this for selection ownership.  */
-extern unsigned long last_event_timestamp;
+extern Time last_event_timestamp;
 
 extern int quit_char;
 
index 705100381d50d3b667c8990b670c31cead61dff0..d2486439fd0984e90723fb93b80c235df0382af1 100644 (file)
@@ -1147,13 +1147,13 @@ no quit occurs and `x-popup-menu' returns nil.  */)
 #else /* not HAVE_X_WINDOWS */
        Lisp_Object bar_window;
        enum scroll_bar_part part;
-       unsigned long time;
+       Time time;
         void (*mouse_position_hook) (struct frame **, int,
                                      Lisp_Object *,
                                      enum scroll_bar_part *,
                                      Lisp_Object *,
                                      Lisp_Object *,
-                                     unsigned long *) =
+                                     Time *) =
          FRAME_TERMINAL (new_f)->mouse_position_hook;
 
        if (mouse_position_hook)
index c3978dae8eb67ffa8daa70c39004364271453301..451401b42d525ae43bbe10c0559a52f2a4c3e667 100644 (file)
@@ -19,6 +19,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef MENU_H
 #define MENU_H
 
+#include "systime.h" /* for Time */
+
 extern void x_set_menu_bar_lines (struct frame *f,
                                   Lisp_Object value,
                                   Lisp_Object oldval);
@@ -48,6 +50,5 @@ extern Lisp_Object w32_menu_show (FRAME_PTR, int, int, int, int,
 extern Lisp_Object ns_menu_show (FRAME_PTR, int, int, int, int,
                                 Lisp_Object, const char **);
 extern Lisp_Object xmenu_show (FRAME_PTR, int, int, int, int,
-                              Lisp_Object, const char **, EMACS_UINT);
+                              Lisp_Object, const char **, Time);
 #endif /* MENU_H */
-
index cb1ea230f7dbc0ac22d3a8451b9d849d43fcd6af..db43b26dc5e53c0190b5d10ce7d5e2c8ceef1470 100644 (file)
@@ -30,6 +30,12 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #endif
 #endif
 
+#ifdef HAVE_X_WINDOWS
+# include <X11/X.h>
+#else
+typedef unsigned long Time;
+#endif
+
 #ifdef HAVE_TZNAME
 #ifndef tzname         /* For SGI.  */
 extern char *tzname[]; /* RS6000 and others want it this way.  */
index c68228cc51aa29bf6353a4c6b1109f4cdd8cad68..34320a1ad6dea0b13ef8b0e9e84b256754d0510a 100644 (file)
@@ -2698,7 +2698,7 @@ term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
 static void
 term_mouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
                     enum scroll_bar_part *part, Lisp_Object *x,
-                    Lisp_Object *y, unsigned long *timeptr)
+                    Lisp_Object *y, Time *timeptr)
 {
   struct timeval now;
 
index 3a49b49aedeb97b0855f1727665da17c806e75cd..34e1364effde5b0cdaeab3e6faa8071a65efee29 100644 (file)
@@ -20,6 +20,8 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 \f
 /* Miscellanea.   */
 
+#include "systime.h" /* for Time */
+
 struct glyph;
 struct frame;
 \f
@@ -233,7 +235,7 @@ struct input_event
   int modifiers;               /* See enum below for interpretation.  */
 
   Lisp_Object x, y;
-  unsigned long timestamp;
+  Time timestamp;
 
   /* This is padding just to put the frame_or_window field
      past the size of struct selection_input_event.  */
@@ -463,7 +465,7 @@ struct terminal
                                enum scroll_bar_part *part,
                                Lisp_Object *x,
                                Lisp_Object *y,
-                               unsigned long *);
+                               Time *);
 
   /* The window system handling code should set this if the mouse has
      moved since the last call to the mouse_position_hook.  Calling that
index ccb60d2dcbbdf7f6952ad2ba22db0c294f54001e..7d7515a8f2552d6ea6f9a6b6183f0df9e66e4763 100644 (file)
@@ -240,7 +240,7 @@ for instance using the window manager, then this produces a quit and
       FRAME_PTR new_f = SELECTED_FRAME ();
       Lisp_Object bar_window;
       enum scroll_bar_part part;
-      unsigned long time;
+      Time time;
       Lisp_Object x, y;
 
       (*mouse_position_hook) (&new_f, 1, &bar_window, &part, &x, &y, &time);
@@ -1420,7 +1420,8 @@ pop_down_menu (Lisp_Object arg)
    menu pops down.
    menu_item_selection will be set to the selection.  */
 static void
-create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, int for_click, EMACS_UINT timestamp)
+create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y,
+                           int for_click, Time timestamp)
 {
   int i;
   GtkWidget *menu;
@@ -1464,7 +1465,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv, int x, int y, i
   gtk_widget_show_all (menu);
 
   gtk_menu_popup (GTK_MENU (menu), 0, 0, pos_func, &popup_x_y, i,
-                 timestamp > 0 ? timestamp : gtk_get_current_event_time());
+                 timestamp ? timestamp : gtk_get_current_event_time ());
 
   record_unwind_protect (pop_down_menu, make_save_value (menu, 0));
 
@@ -1524,7 +1525,7 @@ pop_down_menu (Lisp_Object arg)
    menu_item_selection will be set to the selection.  */
 static void
 create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
-                           int x, int y, int for_click, EMACS_UINT timestamp)
+                           int x, int y, int for_click, Time timestamp)
 {
   int i;
   Arg av[2];
@@ -1598,7 +1599,7 @@ create_and_show_popup_menu (FRAME_PTR f, widget_value *first_wv,
 
 Lisp_Object
 xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
-           Lisp_Object title, const char **error_name, EMACS_UINT timestamp)
+           Lisp_Object title, const char **error_name, Time timestamp)
 {
   int i;
   widget_value *wv, *save_wv = 0, *first_wv = 0, *prev_wv = 0;
@@ -2241,7 +2242,7 @@ pop_down_menu (Lisp_Object arg)
 
 Lisp_Object
 xmenu_show (FRAME_PTR f, int x, int y, int for_click, int keymaps,
-           Lisp_Object title, const char **error_name, EMACS_UINT timestamp)
+           Lisp_Object title, const char **error_name, Time timestamp)
 {
   Window root;
   XMenu *menu;
index f5886ab962803c3991b0cfeeb6cb8164b55e8293..71dc6f1685868db2bbbd051a3aa29f1101300cce 100644 (file)
@@ -342,7 +342,7 @@ static struct scroll_bar *x_window_to_scroll_bar (Display *, Window);
 static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
                                         enum scroll_bar_part *,
                                         Lisp_Object *, Lisp_Object *,
-                                        unsigned long *);
+                                        Time *);
 static void x_handle_net_wm_state (struct frame *, XPropertyEvent *);
 static void x_check_fullscreen (struct frame *);
 static void x_check_expected_move (struct frame *, int, int);
@@ -3799,7 +3799,7 @@ redo_mouse_highlight (void)
 static void
 XTmouse_position (FRAME_PTR *fp, int insist, Lisp_Object *bar_window,
                  enum scroll_bar_part *part, Lisp_Object *x, Lisp_Object *y,
-                 long unsigned int *timestamp)
+                 Time *timestamp)
 {
   FRAME_PTR f1;
 
@@ -5534,7 +5534,7 @@ x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event)
 static void
 x_scroll_bar_report_motion (FRAME_PTR *fp, Lisp_Object *bar_window,
                            enum scroll_bar_part *part, Lisp_Object *x,
-                           Lisp_Object *y, long unsigned int *timestamp)
+                           Lisp_Object *y, Time *timestamp)
 {
   struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
   Window w = bar->x_window;