[Xcb] [PATCH xcb/proto] Revive support for hex literals in protocol

Mikhail Gusarov dottedmag at dottedmag.net
Thu May 13 14:24:27 PDT 2010


As a side-effect it also adds octal and binary literals. Exact syntax is
described at http://docs.python.org/reference/lexical_analysis.html#numbers

It is unwise to use full syntax, as there might be other binding generators,
octal, binary and hex literals seem to be safe though.

Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
---
 xcbgen/expr.py   |    2 +-
 xcbgen/xtypes.py |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/xcbgen/expr.py b/xcbgen/expr.py
index 522e17d..ed4b975 100644
--- a/xcbgen/expr.py
+++ b/xcbgen/expr.py
@@ -77,7 +77,7 @@ class Expression(object):
 
         elif elt.tag == 'value':
             # Constant expression
-            self.nmemb = int(elt.text)
+            self.nmemb = int(elt.text, 0)
 
         else:
             # Notreached
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 01d765e..35fcb91 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -131,7 +131,7 @@ class Enum(SimpleType):
             if value.tag == 'value':
                 self.values.append((item.get('name'), value.text))
             elif value.tag == 'bit':
-                self.values.append((item.get('name'), '%u' % (1 << int(value.text))))
+                self.values.append((item.get('name'), '%u' % (1 << int(value.text, 0))))
                 self.bits.append((item.get('name'), value.text))
 
     def resolve(self, module):
@@ -243,7 +243,7 @@ class PadType(Type):
         Type.__init__(self, tcard8.name)
         self.is_pad = True
         self.size = 1
-        self.nmemb = 1 if (elt == None) else int(elt.get('bytes'))
+        self.nmemb = 1 if (elt == None) else int(elt.get('bytes'), 0)
 
     def resolve(self, module):
         self.resolved = True
-- 
1.7.1



More information about the Xcb mailing list