[Xcb] [PUSHED][PATCH libxcb 1/1] set the align-offset as provided by proto

Christian Linhart chris at DemoRecorder.com
Tue Jan 5 17:20:03 PST 2016


Hi,

I have pushed this patch.
It has got more than enough time for review, so review by crickets applies.

Cheers,

Chris


On 2015-11-01 18:35, Christian Linhart wrote:
> instead of using the lower bits of the pointer address.
> This fixes a bug reported by Peter Hutterer in off-list communication
> back in June 2015.
>
> This requires the alignment-checker patches in xcb/proto.
>
> Signed-off-by: Christian Linhart <chris at demorecorder.com>
> ---
>  src/c_client.py | 18 ++++++++++--------
>  1 file changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/src/c_client.py b/src/c_client.py
> index c38b434..fc34bbe 100644
> --- a/src/c_client.py
> +++ b/src/c_client.py
> @@ -815,15 +815,15 @@ def get_serialize_params(context, self, buffer_var='_buffer', aux_var='_aux'):
>      if not self.is_switch and 'serialize' == context:
>          for p in param_fields:
>              if not p.type.fixed_size():
>                  add_param(params, (p.c_field_const_type, '*', p.c_field_name))
>  
>      return (param_fields, wire_fields, params)
>  
> -def _c_serialize_helper_insert_padding(context, code_lines, space, postpone, is_case_or_bitcase):
> +def _c_serialize_helper_insert_padding(context, complex_type, code_lines, space, postpone, is_case_or_bitcase):
>      code_lines.append('%s    /* insert padding */' % space)
>      if is_case_or_bitcase:
>          code_lines.append(
>              '%s    xcb_pad = -(xcb_block_len + xcb_padding_offset) & (xcb_align_to - 1);'
>              % space)
>      else:
>          code_lines.append(
> @@ -890,15 +890,15 @@ def _c_serialize_helper_switch(context, self, complex_name,
>                                              code_lines, temp_vars,
>                                              "%s    " % space,
>                                              b_prefix,
>                                              is_case_or_bitcase = True)
>          code_lines.append('    }')
>  
>  #    if 'serialize' == context:
> -#        count += _c_serialize_helper_insert_padding(context, code_lines, space, False)
> +#        count += _c_serialize_helper_insert_padding(context, self, code_lines, space, False)
>  #    elif context in ('unserialize', 'unpack', 'sizeof'):
>  #        # padding
>  #        code_lines.append('%s    xcb_pad = -xcb_block_len & 3;' % space)
>  #        code_lines.append('%s    xcb_buffer_len += xcb_block_len + xcb_pad;' % space)
>  
>      return count
>  
> @@ -1164,15 +1164,15 @@ def _c_serialize_helper_fields(context, self,
>                  continue
>  
>          # switch/bitcase: fixed size fields must be considered explicitly
>          if field.type.fixed_size():
>              if self.is_case_or_bitcase or self.c_var_followed_by_fixed_fields:
>                  if prev_field_was_variable and need_padding:
>                      # insert padding
> -#                    count += _c_serialize_helper_insert_padding(context, code_lines, space,
> +#                    count += _c_serialize_helper_insert_padding(context, self, code_lines, space,
>  #                                                                self.c_var_followed_by_fixed_fields)
>                      prev_field_was_variable = False
>  
>                  # prefix for fixed size fields
>                  fixed_prefix = prefix
>  
>                  value, length = _c_serialize_helper_fields_fixed_size(context, self, field,
> @@ -1182,22 +1182,22 @@ def _c_serialize_helper_fields(context, self,
>                  continue
>  
>          # fields with variable size
>          else:
>              if field.type.is_pad:
>                  # Variable length pad is <pad align= />
>                  code_lines.append('%s    xcb_align_to = %d;' % (space, field.type.align))
> -                count += _c_serialize_helper_insert_padding(context, code_lines, space,
> +                count += _c_serialize_helper_insert_padding(context, self, code_lines, space,
>                                                              self.c_var_followed_by_fixed_fields,
>                                                              is_case_or_bitcase)
>                  continue
>              else:
>                  # switch/bitcase: always calculate padding before and after variable sized fields
>                  if need_padding or is_case_or_bitcase:
> -                    count += _c_serialize_helper_insert_padding(context, code_lines, space,
> +                    count += _c_serialize_helper_insert_padding(context, self, code_lines, space,
>                                                                  self.c_var_followed_by_fixed_fields,
>                                                                  is_case_or_bitcase)
>  
>                  value, length = _c_serialize_helper_fields_variable_size(context, self, field,
>                                                                           code_lines, temp_vars,
>                                                                           space, prefix)
>                  prev_field_was_variable = True
> @@ -1281,15 +1281,15 @@ def _c_serialize_helper(context, complex_type,
>              code_lines.append('%s    xcb_buffer_len += xcb_block_len;' % space)
>              code_lines.append('%s    xcb_block_len = 0;' % space)
>  
>          count += _c_serialize_helper_fields(context, self,
>                                              code_lines, temp_vars,
>                                              space, prefix, False)
>      # "final padding"
> -    count += _c_serialize_helper_insert_padding(context, code_lines, space, False, self.is_switch)
> +    count += _c_serialize_helper_insert_padding(context, complex_type, code_lines, space, False, self.is_switch)
>  
>      return count
>  
>  def _c_serialize(context, self):
>      """
>      depending on the context variable, generate _serialize(), _unserialize(), _unpack(), or _sizeof()
>      for the ComplexType variable self
> @@ -1352,15 +1352,16 @@ def _c_serialize(context, self):
>              _c('    unsigned int xcb_buffer_len = sizeof(%s) + xcb_out_pad;', self.c_type)
>              _c('    unsigned int xcb_align_to = 0;')
>          else:
>              _c('    char *xcb_out = *_buffer;')
>              _c('    unsigned int xcb_buffer_len = 0;')
>              _c('    unsigned int xcb_align_to = 0;')
>          if self.is_switch:
> -            _c('    unsigned int xcb_padding_offset = ((size_t)xcb_out) & 7;')
> +            _c('    unsigned int xcb_padding_offset = %d;',
> +	       self.get_align_offset() )
>          prefix = [('_aux', '->', self)]
>          aux_ptr = 'xcb_out'
>  
>      elif context in ('unserialize', 'unpack'):
>          _c('    char *xcb_tmp = (char *)_buffer;')
>          if not self.is_switch:
>              if not self.c_var_followed_by_fixed_fields:
> @@ -1377,15 +1378,16 @@ def _c_serialize(context, self):
>              prefix = [(aux_var, '->', self)]
>          aux_ptr = '*_aux'
>          _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 = 0;')
>          if self.is_switch:
> -            _c('    unsigned int xcb_padding_offset = ((size_t)_buffer) & 7;')
> +            _c('    unsigned int xcb_padding_offset = %d;',
> +	       self.get_align_offset() )
>  
>      elif 'sizeof' == context:
>          param_names = [p[2] for p in params]
>          if self.is_switch:
>              # switch: call _unpack()
>              _c('    %s _aux;', self.c_type)
>              _c('    return %s(%s, &_aux);', self.c_unpack_name, ", ".join(param_names))



More information about the Xcb mailing list