# special case: intermixed fixed and variable size fields
if self.var_followed_by_fixed_fields and 'unserialize' == context:
- value = ' %s = xcb_tmp;' % field.c_field_name
+ value = ' %s = (%s *)xcb_tmp;' % (field.c_field_name, field.c_field_type)
temp_vars.append(' %s *%s;' % (field.type.c_type, field.c_field_name))
# special case: switch
if 'unpack' == context:
return
elif self.var_followed_by_fixed_fields:
# special case: call _unserialize()
- _c(' %s *_aux = NULL;', self.c_type)
- _c(' return %s(%s, &_aux);', self.c_unserialize_name, reduce(lambda x,y: "%s, %s" % (x, y), param_names))
+ _c(' return %s(%s, NULL);', self.c_unserialize_name, reduce(lambda x,y: "%s, %s" % (x, y), param_names))
_c('}')
return
else:
# allocate memory and copy everything into a continuous memory area
# note: this is not necessary in case of unpack
if context in ('serialize', 'unserialize'):
+ # unserialize: check for sizeof-only invocation
+ if 'unserialize' == context:
+ _c('')
+ _c(' if (NULL == _aux)')
+ _c(' return xcb_buffer_len;')
+
_c('')
_c(' if (NULL == %s) {', aux_ptr)
_c(' /* allocate memory */')
# unserialize: assign variable size fields individually
if 'unserialize' == context:
- _c(' *%s = xcb_out;', aux_ptr)
- _c(' xcb_tmp = (char *)(*_aux+1);')
+ _c(' xcb_tmp = ((char *)*_aux)+xcb_buffer_len;')
+ param_fields.reverse()
for field in param_fields:
if not field.type.fixed_size():
- _c(' memcpy(xcb_tmp, %s, %s_len);', field.c_field_name, field.c_field_name)
- _c(' xcb_tmp += %s_len;', field.c_field_name)
+ _c(' xcb_tmp -= %s_len;', field.c_field_name)
+ _c(' memmove(xcb_tmp, %s, %s_len);', field.c_field_name, field.c_field_name)
+ _c(' *%s = xcb_out;', aux_ptr)
_c('')
_c(' return xcb_buffer_len;')