]> code.delx.au - gnu-emacs/commitdiff
Port recent XCB changes to 64-bit ‘long int’
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 13 Nov 2015 17:28:53 +0000 (09:28 -0800)
committerEli Zaretskii <eliz@gnu.org>
Fri, 13 Nov 2015 20:02:13 +0000 (22:02 +0200)
For historical reasons, libX11 represents 32-bit values like Atoms as
‘long int’ even on platforms where ‘long int’ is 64 bits.  XCB doesn’t
do that, so adapt the recent XCB code to behave properly on 64-bit
platforms.  Also, fix what appears to be a bug in the interpretation
of xcb_get_property_value_length, at least on my Fedora platform
which is running libxcb-1.11-5.fc21.
* src/xfns.c (x_real_pos_and_offsets):
* src/xterm.c (get_current_wm_state):
xcb_get_property_value_length returns a byte count, not a word count.
For 32-bit quantities, xcb_get_property_value returns a vector
of 32-bit words, not of (possibly 64-bit) long int.

Backport.

src/xfns.c
src/xterm.c

index 9d90b7ba35fced94965074c07acfad342a8e998b..313ac52f12ae574b5692386479d48db04bd47140 100644 (file)
@@ -450,10 +450,11 @@ x_real_pos_and_offsets (struct frame *f,
           if (prop)
             {
               if (prop->type == target_type
-                  && xcb_get_property_value_length (prop) == 4
-                  && prop->format == 32)
+                  && prop->format == 32
+                  && (xcb_get_property_value_length (prop)
+                     == 4 * sizeof (int32_t)))
                 {
-                  long *fe = xcb_get_property_value (prop);
+                  int32_t *fe = xcb_get_property_value (prop);
 
                   outer_x = -fe[0];
                   outer_y = -fe[2];
index 36a914c85598faf369e1af1bdc3c2a5c4c888f56..acb6566d51dcf12915ff8230a5076f0a4479a7cf 100644 (file)
@@ -10101,17 +10101,19 @@ get_current_wm_state (struct frame *f,
   bool is_hidden = false;
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   long max_len = 65536;
-  unsigned char *tmp_data = NULL;
   Atom target_type = XA_ATOM;
   /* If XCB is available, we can avoid three XSync calls.  */
 #ifdef USE_XCB
   xcb_get_property_cookie_t prop_cookie;
   xcb_get_property_reply_t *prop;
+  xcb_atom_t *reply_data;
 #else
   Display *dpy = FRAME_X_DISPLAY (f);
   unsigned long bytes_remaining;
   int rc, actual_format;
   Atom actual_type;
+  unsigned char *tmp_data = NULL;
+  Atom *reply_data;
 #endif
 
   *sticky = false;
@@ -10126,8 +10128,10 @@ get_current_wm_state (struct frame *f,
   prop = xcb_get_property_reply (dpyinfo->xcb_connection, prop_cookie, NULL);
   if (prop && prop->type == target_type)
     {
-      tmp_data = xcb_get_property_value (prop);
-      actual_size = xcb_get_property_value_length (prop);
+      int actual_bytes = xcb_get_property_value_length (prop);
+      eassume (0 <= actual_bytes);
+      actual_size = actual_bytes / sizeof *reply_data;
+      reply_data = xcb_get_property_value (prop);
     }
   else
     {
@@ -10141,7 +10145,9 @@ get_current_wm_state (struct frame *f,
                            &actual_type, &actual_format, &actual_size,
                            &bytes_remaining, &tmp_data);
 
-  if (rc != Success || actual_type != target_type || x_had_errors_p (dpy))
+  if (rc == Success && actual_type == target_type && ! x_had_errors_p (dpy))
+    reply_data = (Atom *) tmp_data;
+  else
     {
       actual_size = 0;
       is_hidden = FRAME_ICONIFIED_P (f);
@@ -10152,7 +10158,7 @@ get_current_wm_state (struct frame *f,
 
   for (i = 0; i < actual_size; ++i)
     {
-      Atom a = ((Atom*)tmp_data)[i];
+      Atom a = reply_data[i];
       if (a == dpyinfo->Xatom_net_wm_state_hidden)
        is_hidden = true;
       else if (a == dpyinfo->Xatom_net_wm_state_maximized_horz)