[Xcb] [PATCH lib] c_client.py: Handle <sizeof> of fields in unions
Daniel Martin
consume.noise at gmail.com
Thu Jan 3 06:02:36 PST 2013
With this commit the code generator takes care of unions where a field
has the special sizeof element.
Every field of the union will be checked if it contains a sizeof
element. If such an element is found the sizeof function of that field
will be used as sizeof function for the union.
This allows us to implement nearly every list found in XI1 and XI2.
Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
src/c_client.py | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/c_client.py b/src/c_client.py
index 3d521a6..4aa5368 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -1331,8 +1331,22 @@ def _c_iterator(self, name):
_c(' %s *R = i->data;', self.c_type)
if self.is_union:
- # FIXME - how to determine the size of a variable size union??
- _c(' /* FIXME - determine the size of the union %s */', self.c_type)
+ sizeof_field = None
+ for field in self.fields:
+ if hasattr(field.type, 'sizeof_expr') and field.type.sizeof_expr != None:
+ sizeof_field = field.type
+ break
+
+ if sizeof_field:
+ _c(' xcb_generic_iterator_t child;')
+ _c(' child.data = (%s *)(((char *)R) + %s(R));',
+ self.c_type, sizeof_field.c_sizeof_name)
+ _c(' i->index = (char *) child.data - (char *) i->data;')
+ _c(' --i->rem;')
+ _c(' i->data = (%s *) child.data;', self.c_type)
+ else:
+ # FIXME - how to determine the size of a variable size union??
+ _c(' /* FIXME - determine the size of the union %s */', self.c_type)
else:
if self.need_sizeof:
_c(' xcb_generic_iterator_t child;')
--
1.8.0.3
More information about the Xcb
mailing list