X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fc_client.py;h=ad3ea22ea38462de8ba2f18edc364b35d2dd6947;hb=b12038e9ae5343c4176f11d68c963c752bc35c03;hp=3e77e9ef2384924802c81d561c56a7f146be1af3;hpb=294c9f455c3534d836b010dacd2e7aa62a7dde9d;p=free-sw%2Fxcb%2Flibxcb diff --git a/src/c_client.py b/src/c_client.py index 3e77e9e..ad3ea22 100644 --- a/src/c_client.py +++ b/src/c_client.py @@ -171,9 +171,13 @@ def c_open(self): _c('#include ') _c('#include ') _c('#include ') + _c('#include /* for offsetof() */') _c('#include "xcbext.h"') _c('#include "%s.h"', _ns.header) + _c('') + _c('#define ALIGNOF(type) offsetof(struct { char dummy; type member; }, member)') + if _ns.is_ext: for (n, h) in self.imports: _hc('#include "%s.h"', h) @@ -637,7 +641,7 @@ def get_serialize_params(context, self, buffer_var='_buffer', aux_var='_aux'): def _c_serialize_helper_insert_padding(context, code_lines, space, postpone): code_lines.append('%s /* insert padding */' % space) - code_lines.append('%s xcb_pad = -xcb_block_len & 3;' % space) + code_lines.append('%s xcb_pad = -xcb_block_len & (xcb_align_to - 1);' % space) # code_lines.append('%s printf("automatically inserting padding: %%%%d\\n", xcb_pad);' % space) code_lines.append('%s xcb_buffer_len += xcb_block_len + xcb_pad;' % space) @@ -993,6 +997,8 @@ def _c_serialize_helper_fields(context, self, code_lines.append('%s xcb_parts_idx++;' % space) count += 1 + code_lines.append('%s xcb_align_to = ALIGNOF(%s);' % (space, 'char' if field.c_field_type == 'void' else field.c_field_type)) + need_padding = True if self.var_followed_by_fixed_fields: need_padding = False @@ -1100,9 +1106,11 @@ def _c_serialize(context, self): _c(' %s *xcb_out = *_buffer;', self.c_type) _c(' unsigned int xcb_out_pad = -sizeof(%s) & 3;', self.c_type) _c(' unsigned int xcb_buffer_len = sizeof(%s) + xcb_out_pad;', self.c_type) + _c(' unsigned int xcb_align_to;') else: _c(' char *xcb_out = *_buffer;') _c(' unsigned int xcb_buffer_len = 0;') + _c(' unsigned int xcb_align_to;') prefix = [('_aux', '->', self)] aux_ptr = 'xcb_out' @@ -1125,6 +1133,7 @@ def _c_serialize(context, self): _c(' unsigned int xcb_buffer_len = 0;') _c(' unsigned int xcb_block_len = 0;') _c(' unsigned int xcb_pad = 0;') + _c(' unsigned int xcb_align_to;') elif 'sizeof' == context: param_names = [p[2] for p in params] @@ -1169,6 +1178,7 @@ def _c_serialize(context, self): _c(' unsigned int xcb_buffer_len = 0;') _c(' unsigned int xcb_block_len = 0;') _c(' unsigned int xcb_pad = 0;') + _c(' unsigned int xcb_align_to;') _c('') for t in temp_vars: @@ -2290,7 +2300,7 @@ except getopt.GetoptError as err: for (opt, arg) in opts: if opt == '-p': - sys.path.append(arg) + sys.path.insert(1, arg) # Import the module class try: