From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#8664: Being more-systematic about user-interface timestamps Date: Thu, 12 May 2011 13:26:06 -0700 Organization: UCLA Computer Science Department Message-ID: <4DCC425E.2070608@cs.ucla.edu> References: <4DCC3BD6.3000200@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1305232035 25190 80.91.229.12 (12 May 2011 20:27:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 12 May 2011 20:27:15 +0000 (UTC) To: 8664@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu May 12 22:27:10 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QKcTU-0001LR-UZ for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 May 2011 22:27:09 +0200 Original-Received: from localhost ([::1]:45733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKcTU-0005d8-Dy for geb-bug-gnu-emacs@m.gmane.org; Thu, 12 May 2011 16:27:08 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:36984) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKcTQ-0005d3-Ek for bug-gnu-emacs@gnu.org; Thu, 12 May 2011 16:27:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QKcTO-0005Jz-Q8 for bug-gnu-emacs@gnu.org; Thu, 12 May 2011 16:27:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:54496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QKcTO-0005Ju-N3 for bug-gnu-emacs@gnu.org; Thu, 12 May 2011 16:27:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QKcTO-0004Uq-9W; Thu, 12 May 2011 16:27:02 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <4DCC3BD6.3000200@cs.ucla.edu> Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 May 2011 20:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8664 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 8664-submit@debbugs.gnu.org id=B8664.130523197917234 (code B ref 8664); Thu, 12 May 2011 20:27:02 +0000 Original-Received: (at 8664) by debbugs.gnu.org; 12 May 2011 20:26:19 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QKcSg-0004Tu-RL for submit@debbugs.gnu.org; Thu, 12 May 2011 16:26:19 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QKcSc-0004Tf-J3 for 8664@debbugs.gnu.org; Thu, 12 May 2011 16:26:16 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 5155B39E80F9 for <8664@debbugs.gnu.org>; Thu, 12 May 2011 13:26:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9TLN9XqdbgVZ for <8664@debbugs.gnu.org>; Thu, 12 May 2011 13:26:07 -0700 (PDT) Original-Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 1B52E39E80F8 for <8664@debbugs.gnu.org>; Thu, 12 May 2011 13:26:07 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110428 Fedora/3.1.10-1.fc14 Thunderbird/3.1.10 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 12 May 2011 16:27:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46431 Archived-At: Here's a further patch, to make it easier to catch bugs like Bug#8664 in the future. 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 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. === modified file 'src/frame.c' --- src/frame.c 2011-04-19 01:15:59 +0000 +++ src/frame.c 2011-05-12 17:15:05 +0000 @@ -1631,7 +1631,7 @@ 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 @@ 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; === modified file 'src/keyboard.c' --- src/keyboard.c 2011-05-12 19:37:40 +0000 +++ src/keyboard.c 2011-05-12 19:59:08 +0000 @@ -238,7 +238,7 @@ /* 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 @@ 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 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 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 @@ 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)) === modified file 'src/keyboard.h' --- src/keyboard.h 2011-04-14 01:36:53 +0000 +++ src/keyboard.h 2011-05-12 17:08:48 +0000 @@ -16,7 +16,7 @@ You should have received a copy of the GNU General Public License along with GNU Emacs. If not, see . */ -#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 @@ /* 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; === modified file 'src/menu.c' --- src/menu.c 2011-05-12 06:48:32 +0000 +++ src/menu.c 2011-05-12 16:55:07 +0000 @@ -1147,13 +1147,13 @@ #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) === modified file 'src/menu.h' --- src/menu.h 2011-01-25 04:08:28 +0000 +++ src/menu.h 2011-05-12 20:09:02 +0000 @@ -19,6 +19,8 @@ #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 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 */ - === modified file 'src/systime.h' --- src/systime.h 2011-03-11 20:24:09 +0000 +++ src/systime.h 2011-05-12 17:07:49 +0000 @@ -30,6 +30,12 @@ #endif #endif +#ifdef HAVE_X_WINDOWS +# include +#else +typedef unsigned long Time; +#endif + #ifdef HAVE_TZNAME #ifndef tzname /* For SGI. */ extern char *tzname[]; /* RS6000 and others want it this way. */ === modified file 'src/term.c' --- src/term.c 2011-05-04 07:20:46 +0000 +++ src/term.c 2011-05-12 20:16:21 +0000 @@ -2698,7 +2698,7 @@ 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; === modified file 'src/termhooks.h' --- src/termhooks.h 2011-04-25 19:40:22 +0000 +++ src/termhooks.h 2011-05-12 17:13:37 +0000 @@ -20,6 +20,8 @@ /* Miscellanea. */ +#include "systime.h" /* for Time */ + struct glyph; struct frame; @@ -233,7 +235,7 @@ 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 @@ 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 === modified file 'src/xmenu.c' --- src/xmenu.c 2011-05-12 16:16:40 +0000 +++ src/xmenu.c 2011-05-12 16:32:07 +0000 @@ -240,7 +240,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; === modified file 'src/xterm.c' --- src/xterm.c 2011-05-11 23:16:52 +0000 +++ src/xterm.c 2011-05-12 17:01:31 +0000 @@ -342,7 +342,7 @@ 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 @@ 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 @@ 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;