[Xcb] [PATCH v2] Force XCB event structures with 64-bit extended fields to be packed.

Alan Coopersmith alan.coopersmith at oracle.com
Fri Jan 3 14:39:11 PST 2014


On 01/ 3/14 01:31 PM, Kenneth Graunke wrote:
> With the advent of the Present extension, some events (such as
> PresentCompleteNotify) now use native 64-bit types on the wire.

This patch doesn't quite work with the Solaris Studio 12.3 compilers -
they don't accept the __attribute__((__packed__)) coming between the
struct keyword and the struct name and throw a syntax error.

Swapping the ordering to put the attribute before the struct keyword
allowed the build to succeed, but that doesn't result in actual packing, 
when tested with:

    printf("offsetof(xcb_present_complete_notify_event_t,ust)=%d\n",
           offsetof(xcb_present_complete_notify_event_t,ust));
    printf("offsetof(xcb_present_complete_notify_event_t,msc)=%d\n",
           offsetof(xcb_present_complete_notify_event_t,msc));

That printed:
offsetof(xcb_present_complete_notify_event_t,ust)=24
offsetof(xcb_present_complete_notify_event_t,msc)=40

unless the XCB_PACKED came *after* the struct, as in:
typedef struct xcb_present_complete_notify_event_t {
...
} XCB_PACKED xcb_present_complete_notify_event_t;

which made it print:
offsetof(xcb_present_complete_notify_event_t,ust)=24
offsetof(xcb_present_complete_notify_event_t,msc)=36

so I think this change is necessary - would you like to include it in your
patch, or for me to apply as a follow on fix for Solaris Studio?

diff --git a/src/c_client.py b/src/c_client.py
index 7adfcd1..45de544 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -1772,7 +1772,7 @@ def _c_complex(self, force_packed = False):
     _h('/**')
     _h(' * @brief %s', self.c_type)
     _h(' **/')
-    _h('typedef %s%s %s {', self.c_container, ' XCB_PACKED' if force_packed else '', self.c_type)
+    _h('typedef %s %s {', self.c_container, self.c_type)
 
     struct_fields = []
     maxtypelen = 0
@@ -1817,7 +1817,7 @@ def _c_complex(self, force_packed = False):
             if b.type.has_name:
                 _h('    } %s;', b.c_field_name)
 
-    _h('} %s;', self.c_type)
+    _h('} %s%s;', 'XCB_PACKED ' if force_packed else '', self.c_type)
 
 def c_struct(self, name):
     '''

-- 
	-Alan Coopersmith-              alan.coopersmith at oracle.com
	 Oracle Solaris Engineering - http://blogs.oracle.com/alanc


More information about the Xcb mailing list