[Xcb] [PATCH] Don't try to sizeof(void)

Peter Harris pharris at opentext.com
Thu Dec 23 10:42:06 PST 2010


sizeof(void) is a gcc extension, and not portable.

Xorg Bugzilla 31959
http://bugs.freedesktop.org/show_bug.cgi?id=31959
http://lists.freedesktop.org/archives/xcb/2010-May/006039.html

Signed-off-by: Peter Harris <pharris at opentext.com>
---
In the long term I'd like to see the void type removed entirely, to be
replaced by <switch> (or whatever is necessary) in each instance.

Until that magical day, this stop-gap may help.

My python-fu is weak. Review most welcome.

 src/c_client.py |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/c_client.py b/src/c_client.py
index 91719b7..a10b3f1 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -1423,6 +1423,11 @@ def _c_accessor_get_expr(expr, field_mapping):
     else:
         return lenexp
 
+def type_pad_type(type):
+    if type == 'void':
+        return 'char'
+    return type
+
 def _c_accessors_field(self, field):
     '''
     Declares the accessor functions for a non-list field that follows a variable-length field.
@@ -1457,7 +1462,7 @@ def _c_accessors_field(self, field):
         else:
             _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
             _c('    return * (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', 
-               field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+               field.c_field_type, type_pad_type(field.first_field_after_varsized.type.c_type), field.prev_varsized_offset)
         _c('}')
     else:
         _hc('')
@@ -1488,7 +1493,7 @@ def _c_accessors_field(self, field):
         else:
             _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
             _c('    return (%s) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', 
-               return_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+               return_type, type_pad_type(field.first_field_after_varsized.type.c_type), field.prev_varsized_offset)
         _c('}')
 
     
@@ -1575,7 +1580,7 @@ def _c_accessors_list(self, field):
         else:
             _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
             _c('    return (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index) + %d);', 
-               field.c_field_type, field.first_field_after_varsized.type.c_type, field.prev_varsized_offset)
+               field.c_field_type, type_pad_type(field.first_field_after_varsized.type.c_type), field.prev_varsized_offset)
         _c('}')
 
     _hc('')
@@ -1679,7 +1684,7 @@ def _c_accessors_list(self, field):
         else:
             _c('    xcb_generic_iterator_t prev = %s;', _c_iterator_get_end(field.prev_varsized_field, 'R'))
             _c('    i.data = (%s *) ((char *) prev.data + XCB_TYPE_PAD(%s, prev.index));', 
-               field.c_field_type, field.c_field_type)
+               field.c_field_type, type_pad_type(field.c_field_type))
         if switch_obj is None:
             _c('    i.rem = %s;', _c_accessor_get_expr(field.type.expr, fields))
         _c('    i.index = (char *) i.data - (char *) %s;', 'R' if switch_obj is None else 'S' )
-- 
1.7.2.3



More information about the Xcb mailing list