[Xcb] [PATCH libxcb 1/3 V2] generator: support fixed size lists in var-sized structs

Ran Benita ran234 at gmail.com
Tue Sep 9 09:38:46 PDT 2014


On Sat, Sep 06, 2014 at 08:06:15PM +0200, Christian Linhart wrote:
> V2: patch revised according to suggestions from Ran Benita:
> * removed blanks before an after parentheses of function-calls or tuples
> * replaced if by elif in "if field.type.is_list". ( this fixes old code )

Reviewed-by: Ran Benita <ran234 at gmail.com>

(With the style fixes in QueryDeviceState-V3 branch).

> 
> ---
>  src/c_client.py | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/c_client.py b/src/c_client.py
> index 87f268b..fa59fff 100644
> --- a/src/c_client.py
> +++ b/src/c_client.py
> @@ -866,16 +866,20 @@ def _c_serialize_helper_fields_fixed_size(context, self, field,
>              for i in range(field.type.nmemb):
>                  code_lines.append('%s    %s[%d] = *(%s *)xcb_tmp;' %
>                                    (space, abs_field_name, i, field.c_field_type))
>              # total padding = sizeof(pad0) * nmemb
>              length += " * %d" % field.type.nmemb
>  
> -        if field.type.is_list:
> +        elif field.type.is_list:
> -            # no such case in the protocol, cannot be tested and therefore ignored for now
> -            raise Exception('list with fixed number of elemens unhandled in _unserialize()')
> +            #list with fixed number of elements
> +            #length of array = sizeof(arrayElementType) * nmemb
> +            length += " * %d" % field.type.nmemb
> +            #use memcpy because C cannot assign whole arrays with operator=
> +            value = '    memcpy(%s, xcb_tmp, %s);' % (abs_field_name, length)
> +
>  
>      elif 'serialize' == context:
>          value = '    xcb_parts[xcb_parts_idx].iov_base = (char *) '
>  
>          if field.type.is_expr:
>              # need to register a temporary variable for the expression in case we know its type
>              if field.type.c_type is None:
> -- 2.0.1
> 
> 


More information about the Xcb mailing list