[Xcb-commit] libxcb: 4 commits - src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Sep 20 18:38:37 UTC 2021


 src/c_client.py |   97 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 61 insertions(+), 36 deletions(-)

New commits:
commit 3c76c0579ffa521af41f78ee937b1337581da985
Author: Povilas Kanapickas <povilas at radix.lt>
Date:   Fri Jul 30 22:58:47 2021 +0300

    c_client.py: Implement handling of <length> element
    
    Signed-off-by: Povilas Kanapickas <povilas at radix.lt>

diff --git a/src/c_client.py b/src/c_client.py
index 6b7e32c..dfb5864 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -1417,6 +1417,16 @@ def _c_serialize(context, self):
 
     elif 'sizeof' == context:
         param_names = [p[2] for p in params]
+        if self.length_expr is not None:
+            _c('    const %s *_aux = (%s *)_buffer;', self.c_type, self.c_type)
+            prefix = [('_aux', '->', self)]
+
+            field_mapping = _c_get_field_mapping_for_expr(self, self.length_expr, prefix)
+
+            _c('    return %s;', _c_accessor_get_expr(self.length_expr, field_mapping))
+            _c('}')
+            _c_pre.redirect_end()
+            return
         if self.is_switch:
             # switch: call _unpack()
             _c('    %s _aux;', self.c_type)
commit bdc3f21a5205293852bbaa173f43389cbf66f52b
Author: Povilas Kanapickas <povilas at radix.lt>
Date:   Fri Jul 30 22:58:46 2021 +0300

    c_client: Extract _c_get_field_mapping_for_expr()

diff --git a/src/c_client.py b/src/c_client.py
index 26e2ff7..6b7e32c 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -966,18 +966,15 @@ def _c_get_additional_type_params(type):
         param_fields, wire_fields, params = get_serialize_params('sizeof', type)
         return params[1:]
 
-def _c_serialize_helper_list_field(context, self, field,
-                                   code_lines, temp_vars,
-                                   space, prefix):
+
+def _c_get_field_mapping_for_expr(self, expr, prefix):
     """
-    helper function to cope with lists of variable length
+    helper function to get field mapping of a particular expression.
     """
-    expr = field.type.expr
-    prefix_str = _c_helper_fieldaccess_expr(prefix)
     param_fields, wire_fields, params = get_serialize_params('sizeof', self)
     param_names = [p[2] for p in params]
 
-    expr_fields_names = get_expr_field_names(field.type.expr)
+    expr_fields_names = get_expr_field_names(expr)
     resolved = [x for x in expr_fields_names if x in param_names]
     unresolved = [x for x in expr_fields_names if x not in param_names]
 
@@ -996,6 +993,21 @@ def _c_serialize_helper_list_field(context, self, field,
         unresolved = [x for x in unresolved if x not in field_mapping]
         if len(unresolved)>0:
             raise Exception('could not resolve the length fields required for list %s' % field.c_field_name)
+
+    return field_mapping
+
+
+def _c_serialize_helper_list_field(context, self, field,
+                                   code_lines, temp_vars,
+                                   space, prefix):
+    """
+    helper function to cope with lists of variable length
+    """
+    expr = field.type.expr
+    prefix_str = _c_helper_fieldaccess_expr(prefix)
+
+    field_mapping = _c_get_field_mapping_for_expr(self, field.type.expr, prefix)
+
     if expr.op == 'calculate_len':
         list_length = field.type.expr.lenfield_name
     else:
commit 068af21cb376eb824fa1dee29a6539feadb93587
Author: Povilas Kanapickas <povilas at radix.lt>
Date:   Fri Jul 30 22:58:45 2021 +0300

    c_client.py: Use get_expr_field_names directly to resolve list fields
    
    Using get_expr_fields() is only needed in case we are doing things that
    can span multiple types easily, e.g. when deciding what data to pass via
    function parameters and so on.
    
    In _c_serialize_helper_list_field() we are building function body, so
    acquiring field names via get_expr_field_names() is enough.
    
    Signed-off-by: Povilas Kanapickas <povilas at radix.lt>

diff --git a/src/c_client.py b/src/c_client.py
index b987f4e..26e2ff7 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -977,7 +977,7 @@ def _c_serialize_helper_list_field(context, self, field,
     param_fields, wire_fields, params = get_serialize_params('sizeof', self)
     param_names = [p[2] for p in params]
 
-    expr_fields_names = [f.field_name for f in get_expr_fields(field.type)]
+    expr_fields_names = get_expr_field_names(field.type.expr)
     resolved = [x for x in expr_fields_names if x in param_names]
     unresolved = [x for x in expr_fields_names if x not in param_names]
 
commit 4d678b162bf8a3b10e5bdf76df2be63d33c23381
Author: Povilas Kanapickas <povilas at radix.lt>
Date:   Fri Jul 30 22:58:44 2021 +0300

    c_client.py: Extract get_expr_field_names()
    
    Signed-off-by: Povilas Kanapickas <povilas at radix.lt>

diff --git a/src/c_client.py b/src/c_client.py
index 39f162e..b987f4e 100644
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -649,39 +649,42 @@ def _c_helper_resolve_field_names (prefix):
 
     return all_fields
 
+
+def get_expr_field_names(expr):
+    """
+    returns a list of field names referenced in an expression
+    """
+    if expr.op is None or expr.op == 'calculate_len':
+        if expr.lenfield_name is not None:
+            return [expr.lenfield_name]
+        # constant value expr
+        return []
+
+    if expr.op == '~':
+        return get_expr_field_names(expr.rhs)
+    if expr.op == 'popcount':
+        return get_expr_field_names(expr.rhs)
+    if expr.op == 'sumof':
+        # sumof expr references another list,
+        # we need that list's length field here
+        field = None
+        for f in expr.lenfield_parent.fields:
+            if f.field_name == expr.lenfield_name:
+                field = f
+                break
+        if field is None:
+            raise Exception("list field '%s' referenced by sumof not found" % expr.lenfield_name)
+        # referenced list + its length field
+        return [expr.lenfield_name] + get_expr_field_names(field.type.expr)
+    if expr.op == 'enumref':
+        return []
+    return get_expr_field_names(expr.lhs) + get_expr_field_names(expr.rhs)
+
+
 def get_expr_fields(self):
     """
     get the Fields referenced by switch or list expression
     """
-    def get_expr_field_names(expr):
-        if expr.op is None or expr.op == 'calculate_len':
-            if expr.lenfield_name is not None:
-                return [expr.lenfield_name]
-            else:
-                # constant value expr
-                return []
-        else:
-            if expr.op == '~':
-                return get_expr_field_names(expr.rhs)
-            elif expr.op == 'popcount':
-                return get_expr_field_names(expr.rhs)
-            elif expr.op == 'sumof':
-                # sumof expr references another list,
-                # we need that list's length field here
-                field = None
-                for f in expr.lenfield_parent.fields:
-                    if f.field_name == expr.lenfield_name:
-                        field = f
-                        break
-                if field is None:
-                    raise Exception("list field '%s' referenced by sumof not found" % expr.lenfield_name)
-                # referenced list + its length field
-                return [expr.lenfield_name] + get_expr_field_names(field.type.expr)
-            elif expr.op == 'enumref':
-                return []
-            else:
-                return get_expr_field_names(expr.lhs) + get_expr_field_names(expr.rhs)
-    # get_expr_field_names()
 
     # resolve the field names with the parent structure(s)
     unresolved_fields_names = get_expr_field_names(self.expr)


More information about the xcb-commit mailing list