[Xcb] [PATCH 2/2: xpyb] Fix length field handling, again.

Alex Plotnick shrike at netaxs.com
Fri Mar 23 07:19:09 PDT 2012


This revises commit c5ff7fbf5a53cc20984a20d5461be2fc1f1eac39, which did
fix the build, but generated invalid code for (at least) QueryTextExtents.
---
This patch depends on the patch renaming the "parent" attribute of
xcbgen.ExprType to "parents".

As an aside, I'm pretty sure this code is correct only for the special case
of QueryTextExtents, where the Request object happens to be the grandparent
of the given expr. We should probably do a recursive search up the ancestor
tree for a Request instance to avoid the special case. However, this patch
preserves the existing logic, special-cased or not; it just fixes it.

I would also really prefer to use isinstance(x, Request) rather than the
kludgey test for the presence of the "opcode" attribute, but again, in the
interest of minimal changes, I've held off on that. If no one objects (or,
better, if anyone encourages it), I'll submit a separate patch that
addresses some of these issues.

 src/py_client.py |   16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/py_client.py b/src/py_client.py
index d132f43..358df49 100755
--- a/src/py_client.py
+++ b/src/py_client.py
@@ -259,16 +259,12 @@ def _py_get_length_field(expr):
     For fields that follow a variable-length field, use the accessor.
     Otherwise, just reference the structure field directly.
     '''
-    if expr.lenfield_name != None:
-        # This would be nicer if Request had an is_request attribute...
-        try:
-            has_opcode = hasattr(expr.parent.parents, "opcode")
-        except AttributeError:
-            has_opcode = False
-        if has_opcode:
-            return expr.lenfield_name
-        else:
-            return 'self.%s' % expr.lenfield_name
+    if expr.lenfield_name is not None:
+        for grandparent in expr.parent.parents:
+            # This would be nicer if Request had an is_request attribute...
+            if hasattr(grandparent, "opcode"):
+                return expr.lenfield_name
+        return 'self.%s' % expr.lenfield_name
     else:
         return str(expr.nmemb)
 
-- 
1.7.9.2



More information about the Xcb mailing list