[Xcb] [PATCH libxcb 1/4] generator: no type-setup for eventcopies anymore

Christian Linhart chris at demorecorder.com
Thu Sep 4 08:50:48 PDT 2014


_c_type_setup is not called for eventcopies anymore:
Reasons:
* the type-setup of an eventcopy would overwrite members of the original
  event object such as c_type, ...
* it is needed for the next patch, i.e., generating accessors:
  type_setup would create sizeof-etc funtions which called
  undefined accessor functions.

Sizeof-functions are generated for compatibility:
Reason:
* Type-setup of eventcopies has previously generated
  sizeof-functions for eventcopies.
  So, we still need to generate these functions.
  These new sizeof-functions simply call the sizeof-function
  of the defining event of the eventcopy.
---
 src/c_client.py | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/c_client.py b/src/c_client.py
index 34b427e..ab0b59e 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -3081,27 +3081,50 @@ def c_event(self, name):
 
                 # If the event contains any 64-bit extended fields, they need
                 # to remain aligned on a 64-bit boundary.  Adding full_sequence
                 # would normally break that; force the struct to be packed.
                 force_packed = any(f.type.size == 8 and f.type.is_simple for f in self.fields[(idx+1):])
                 break
 
-    _c_type_setup(self, name, ('event',))
+    if self.name == name:
+        _c_type_setup(self, name, ('event',))
+    else:
+        #no type-setup needed for eventcopies
+        #(the type-setup of an eventcopy would overwrite members of the original
+        #event, and it would create sizeof-etc funtions which
+        #called undefined accessor functions)
+        pass
 
     # Opcode define
     _c_opcode(name, self.opcodes[name])
 
     if self.name == name:
         # Structure definition
         _c_complex(self, force_packed)
     else:
         # Typedef
         _h('')
         _h('typedef %s %s;', _t(self.name + ('event',)), _t(name + ('event',)))
 
+        #Create sizeof-function for eventcopies for compatibility reasons
+        if self.c_need_sizeof:
+            _h_setlevel(1)
+            _c_setlevel(1)
+            _h('')
+            _h('int')
+            _h('%s (const void  *_buffer  /**< */);', _n(name + ('sizeof',)))
+            _c('')
+            _c('int')
+            _c('%s (const void  *_buffer  /**< */)', _n(name + ('sizeof',)))
+            _c('{');
+            _c('    return %s(_buffer);', _n(self.name + ('sizeof',)))
+            _c('}');
+            _h_setlevel(0)
+            _c_setlevel(0)
+
     _man_event(self, name)
 
 def c_error(self, name):
     '''
     Exported function that handles error declarations.
     '''
     _c_type_setup(self, name, ('error',))
-- 
2.0.1



More information about the Xcb mailing list