[Xcb] [PATCH xpyb] Pack requests using standard size and no alignment.

Alex Plotnick shrike at netaxs.com
Fri Mar 23 07:40:14 PDT 2012


By default, Python's struct module automatically adds alignment padding
between successive structure members. We need precise control over the
layout of requests, so it's important that we not let it do that.
---
In conjunction with my last two patches ('Rename the ExprType "parent"
attribute to "parents"' and 'Fix length field handling, again'), this
patch finally fixes QueryTextExtents on my 64-bit system. Without it,
the request contains a spurious padding byte and is unintelligible to
the server.

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

diff --git a/src/py_client.py b/src/py_client.py
index d132f43..5a7aa0c 100755
--- a/src/py_client.py
+++ b/src/py_client.py
@@ -486,24 +486,24 @@ def _py_request_helper(self, name, void, regular):
 
         (format, size, list) = _py_flush_format()
         if size > 0:
-            _py('        buf.write(pack(\'%s\', %s))', format, list)
+            _py('        buf.write(pack(\'=%s\', %s))', format, list)
 
         if field.type.is_expr:
-            _py('        buf.write(pack(\'%s\', %s))', field.type.py_format_str, _py_get_expr(field.type.expr))
+            _py('        buf.write(pack(\'=%s\', %s))', field.type.py_format_str, _py_get_expr(field.type.expr))
         elif field.type.is_pad:
             _py('        buf.write(pack(\'%sx\'))', field.type.nmemb)
         elif field.type.is_container:
             _py('        for elt in xcb.Iterator(%s, %d, \'%s\', False):', _n(field.field_name), field.type.py_format_len, _n(field.field_name))
-            _py('            buf.write(pack(\'%s\', *elt))', field.type.py_format_str)
+            _py('            buf.write(pack(\'=%s\', *elt))', field.type.py_format_str)
         elif field.type.is_list and field.type.member.is_simple:
             _py('        buf.write(str(buffer(array(\'%s\', %s))))', field.type.member.py_format_str, _n(field.field_name))
         else:
             _py('        for elt in xcb.Iterator(%s, %d, \'%s\', True):', _n(field.field_name), field.type.member.py_format_len, _n(field.field_name))
-            _py('            buf.write(pack(\'%s\', *elt))', field.type.member.py_format_str)
+            _py('            buf.write(pack(\'=%s\', *elt))', field.type.member.py_format_str)
 
     (format, size, list) = _py_flush_format()
     if size > 0:
-        _py('        buf.write(pack(\'%s\', %s))', format, list)
+        _py('        buf.write(pack(\'=%s\', %s))', format, list)
 
     _py('        return self.send_request(xcb.Request(buf.getvalue(), %s, %s, %s),', self.opcode, _b(void), _b(func_flags))
     _py('                                 %s()%s', func_cookie, ')' if void else ',')
-- 
1.7.9.2



More information about the Xcb mailing list