--- src/ChangeLog | 11 +++++++++++ src/xselect.c | 42 ++++++++++++++++++++++++------------------ src/xterm.c | 20 ++++++++++---------- src/xterm.h | 16 ++++++++++++++++ 4 files changed, 61 insertions(+), 28 deletions(-) --- src/ChangeLog +++ src/ChangeLog 2014-10-03 02:20:52.000000000 +0000 @@ -30,6 +30,17 @@ (font_matching_entity): Likewise. If matching entity is found, insert 1-item vector with this entity instead of an entity itself (Bug#17125). +2014-10-03 Paul Eggert + + Fix x-focus-frame bug with "Not an in-range integer" (Bug#18586). + * xselect.c (X_SHRT_MAX, X_SHRT_MIN, X_LONG_MAX, X_LONG_MIN) + (X_ULONG_MAX): Move these macros to xterm.h. + (x_fill_property_data): Be more generous about allowing either + signed or unsigned data of the appropriate width. + * xterm.h (x_display_set_last_user_time): New function. + All setters of last_user_time changd to use this function. + If ENABLE_CHECKING, check that the times are in range. + 2014-10-02 Eli Zaretskii * xdisp.c (move_it_by_lines): Call reseat_1 after moving the --- src/xselect.c +++ src/xselect.c 2014-10-29 11:09:29.000000000 +0000 @@ -97,13 +97,6 @@ static Lisp_Object Qx_lost_selection_fun is not necessarily sizeof (long). */ #define X_LONG_SIZE 4 -/* Extreme 'short' and 'long' values suitable for libX11. */ -#define X_SHRT_MAX 0x7fff -#define X_SHRT_MIN (-1 - X_SHRT_MAX) -#define X_LONG_MAX 0x7fffffff -#define X_LONG_MIN (-1 - X_LONG_MAX) -#define X_ULONG_MAX 0xffffffffUL - /* If this is a smaller number than the max-request-size of the display, emacs will use INCR selection transfer when the selection is larger than this. The max-request-size is usually around 64k, so if you want @@ -2307,10 +2300,10 @@ x_check_property_data (Lisp_Object data) void x_fill_property_data (Display *dpy, Lisp_Object data, void *ret, int format) { - long val; - long *d32 = (long *) ret; - short *d16 = (short *) ret; - char *d08 = (char *) ret; + unsigned long val; + unsigned long *d32 = (unsigned long *) ret; + unsigned short *d16 = (unsigned short *) ret; + unsigned char *d08 = (unsigned char *) ret; Lisp_Object iter; for (iter = data; CONSP (iter); iter = XCDR (iter)) @@ -2318,7 +2311,22 @@ x_fill_property_data (Display *dpy, Lisp Lisp_Object o = XCAR (iter); if (INTEGERP (o) || FLOATP (o) || CONSP (o)) - val = cons_to_signed (o, LONG_MIN, LONG_MAX); + { + if (CONSP (o) + && RANGED_INTEGERP (X_LONG_MIN >> 16, XCAR (o), X_LONG_MAX >> 16) + && RANGED_INTEGERP (- (1 << 15), XCDR (o), -1)) + { + /* cons_to_x_long does not handle negative values for v2. + For XDnd, v2 might be y of a window, and can be negative. + The XDnd spec. is not explicit about negative values, + but let's assume negative v2 is sent modulo 2**16. */ + unsigned long v1 = XINT (XCAR (o)) & 0xffff; + unsigned long v2 = XINT (XCDR (o)) & 0xffff; + val = (v1 << 16) | v2; + } + else + val = cons_to_x_long (o); + } else if (STRINGP (o)) { block_input (); @@ -2330,17 +2338,15 @@ x_fill_property_data (Display *dpy, Lisp if (format == 8) { - if (CHAR_MIN <= val && val <= CHAR_MAX) - *d08++ = val; - else + if ((1 << 8) < val && val <= X_ULONG_MAX - (1 << 7)) error ("Out of 'char' range"); + *d08++ = val; } else if (format == 16) { - if (SHRT_MIN <= val && val <= SHRT_MAX) - *d16++ = val; - else + if ((1 << 16) < val && val <= X_ULONG_MAX - (1 << 15)) error ("Out of 'short' range"); + *d16++ = val; } else *d32++ = val; --- src/xterm.c +++ src/xterm.c 2014-10-03 02:20:52.000000000 +0000 @@ -5961,7 +5961,7 @@ handle_one_xevent (struct x_display_info break; case SelectionNotify: - dpyinfo->last_user_time = event->xselection.time; + x_display_set_last_user_time (dpyinfo, event->xselection.time); #ifdef USE_X_TOOLKIT if (! x_window_to_frame (dpyinfo, event->xselection.requestor)) goto OTHER; @@ -5970,7 +5970,7 @@ handle_one_xevent (struct x_display_info break; case SelectionClear: /* Someone has grabbed ownership. */ - dpyinfo->last_user_time = event->xselectionclear.time; + x_display_set_last_user_time (dpyinfo, event->xselectionclear.time); #ifdef USE_X_TOOLKIT if (! x_window_to_frame (dpyinfo, event->xselectionclear.window)) goto OTHER; @@ -5986,7 +5986,7 @@ handle_one_xevent (struct x_display_info break; case SelectionRequest: /* Someone wants our selection. */ - dpyinfo->last_user_time = event->xselectionrequest.time; + x_display_set_last_user_time (dpyinfo, event->xselectionrequest.time); #ifdef USE_X_TOOLKIT if (!x_window_to_frame (dpyinfo, event->xselectionrequest.owner)) goto OTHER; @@ -6005,7 +6005,7 @@ handle_one_xevent (struct x_display_info break; case PropertyNotify: - dpyinfo->last_user_time = event->xproperty.time; + x_display_set_last_user_time (dpyinfo, event->xproperty.time); f = x_top_window_to_frame (dpyinfo, event->xproperty.window); if (f && event->xproperty.atom == dpyinfo->Xatom_net_wm_state) if (x_handle_net_wm_state (f, &event->xproperty) @@ -6193,7 +6193,7 @@ handle_one_xevent (struct x_display_info case KeyPress: - dpyinfo->last_user_time = event->xkey.time; + x_display_set_last_user_time (dpyinfo, event->xkey.time); ignore_next_mouse_click_timeout = 0; #if defined (USE_X_TOOLKIT) || defined (USE_GTK) @@ -6527,7 +6527,7 @@ handle_one_xevent (struct x_display_info #endif case KeyRelease: - dpyinfo->last_user_time = event->xkey.time; + x_display_set_last_user_time (dpyinfo, event->xkey.time); #ifdef HAVE_X_I18N /* Don't dispatch this event since XtDispatchEvent calls XFilterEvent, and two calls in a row may freeze the @@ -6538,7 +6538,7 @@ handle_one_xevent (struct x_display_info #endif case EnterNotify: - dpyinfo->last_user_time = event->xcrossing.time; + x_display_set_last_user_time (dpyinfo, event->xcrossing.time); x_detect_focus_change (dpyinfo, any, event, &inev.ie); f = any; @@ -6563,7 +6563,7 @@ handle_one_xevent (struct x_display_info goto OTHER; case LeaveNotify: - dpyinfo->last_user_time = event->xcrossing.time; + x_display_set_last_user_time (dpyinfo, event->xcrossing.time); x_detect_focus_change (dpyinfo, any, event, &inev.ie); f = x_top_window_to_frame (dpyinfo, event->xcrossing.window); @@ -6597,7 +6597,7 @@ handle_one_xevent (struct x_display_info case MotionNotify: { - dpyinfo->last_user_time = event->xmotion.time; + x_display_set_last_user_time (dpyinfo, event->xmotion.time); previous_help_echo_string = help_echo_string; help_echo_string = Qnil; @@ -6738,7 +6738,7 @@ handle_one_xevent (struct x_display_info memset (&compose_status, 0, sizeof (compose_status)); dpyinfo->last_mouse_glyph_frame = NULL; - dpyinfo->last_user_time = event->xbutton.time; + x_display_set_last_user_time (dpyinfo, event->xbutton.time); f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame : x_window_to_frame (dpyinfo, event->xbutton.window)); --- src/xterm.h +++ src/xterm.h 2014-10-03 02:20:52.000000000 +0000 @@ -644,6 +644,13 @@ struct x_output int move_offset_left; }; +/* Extreme 'short' and 'long' values suitable for libX11. */ +#define X_SHRT_MAX 0x7fff +#define X_SHRT_MIN (-1 - X_SHRT_MAX) +#define X_LONG_MAX 0x7fffffff +#define X_LONG_MIN (-1 - X_LONG_MAX) +#define X_ULONG_MAX 0xffffffffUL + #define No_Cursor (None) enum @@ -959,6 +966,15 @@ extern int x_x_to_emacs_modifiers (struc extern int x_display_pixel_height (struct x_display_info *); extern int x_display_pixel_width (struct x_display_info *); +INLINE void +x_display_set_last_user_time (struct x_display_info *dpyinfo, Time t) +{ +#ifdef ENABLE_CHECKING + eassert (t <= X_ULONG_MAX); +#endif + dpyinfo->last_user_time = t; +} + extern void x_set_sticky (struct frame *, Lisp_Object, Lisp_Object); extern void x_wait_for_event (struct frame *, int);