[Xcb-commit] xcb/proto: xcbgen

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Dec 28 08:32:17 UTC 2019


 xcbgen/state.py  |    6 +++---
 xcbgen/xtypes.py |   35 +++++++++++++++++++----------------
 2 files changed, 22 insertions(+), 19 deletions(-)

New commits:
commit e79f6b01e04f704c9f158e074ec2654407eae8e4
Author: Uli Schlachter <psychon at znc.in>
Date:   Sat Nov 2 14:50:04 2019 +0100

    Allow access to the original type in the XML
    
    xcbgen 'helpfully' transforms things to C types already so that libxcb
    does not have to do so. Thus, even though the XML says that a field has
    type CARD8, xcbgen will claim uint8_t. This might be a bit weird, but is
    so far totally fine.
    
    However, the type mapping that xcbgen uses is not injective. All of
    CARD8, BYTE and BOOL get turned into uint8_t and the original type is
    lost.
    
    This is totally fine for libxcb, but programming languages other than C
    do have built in boolean types. My personal problem is with Rust, where
    providing a boolean for an integer argument causes a compiler error.
    This results in (relatively) ugly "0 / 1" instead of "false / true".
    
    This commit adds a new xml_type member to SimpleType. This type contains
    the original string that appeared in the XML file.
    
    Since libxcb creates instances of SimpleType itself and to avoid
    breaking the API, the new argument to SimpleType.__init__ defaults to
    None.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/xcbgen/state.py b/xcbgen/state.py
index a8346bb..0dbecdc 100644
--- a/xcbgen/state.py
+++ b/xcbgen/state.py
@@ -100,12 +100,12 @@ class Module(object):
         self.add_type('INT16', '', ('int16_t',), tint16)
         self.add_type('INT32', '', ('int32_t',), tint32)
         self.add_type('INT64', '', ('int64_t',), tint64)
-        self.add_type('BYTE', '', ('uint8_t',), tcard8)
-        self.add_type('BOOL', '', ('uint8_t',), tcard8)
+        self.add_type('BYTE', '', ('uint8_t',), tbyte)
+        self.add_type('BOOL', '', ('uint8_t',), tbool)
         self.add_type('char', '', ('char',), tchar)
         self.add_type('float', '', ('float',), tfloat)
         self.add_type('double', '', ('double',), tdouble)
-        self.add_type('void', '', ('void',), tcard8)
+        self.add_type('void', '', ('void',), tvoid)
 
     # This goes out and parses the rest of the XML
     def register(self):
diff --git a/xcbgen/xtypes.py b/xcbgen/xtypes.py
index 8a9d130..3afc812 100644
--- a/xcbgen/xtypes.py
+++ b/xcbgen/xtypes.py
@@ -192,12 +192,12 @@ class SimpleType(PrimitiveType):
     Any type which is typedef'ed to cardinal will be one of these.
 
     Public fields added:
-    none
+    xml_type is the original string describing the type in the XML
     '''
-    def __init__(self, name, size):
+    def __init__(self, name, size, xml_type=None):
         PrimitiveType.__init__(self, name, size)
         self.is_simple = True
-
+        self.xml_type = xml_type
 
     def resolve(self, module):
         self.resolved = True
@@ -206,24 +206,27 @@ class SimpleType(PrimitiveType):
 
 
 # Cardinal datatype globals.  See module __init__ method.
-tcard8 = SimpleType(('uint8_t',), 1)
-tcard16 = SimpleType(('uint16_t',), 2)
-tcard32 = SimpleType(('uint32_t',), 4)
-tcard64 = SimpleType(('uint64_t',), 8)
-tint8 =  SimpleType(('int8_t',), 1)
-tint16 = SimpleType(('int16_t',), 2)
-tint32 = SimpleType(('int32_t',), 4)
-tint64 = SimpleType(('int64_t',), 8)
-tchar =  SimpleType(('char',), 1)
-tfloat = SimpleType(('float',), 4)
-tdouble = SimpleType(('double',), 8)
+tcard8 = SimpleType(('uint8_t',), 1, 'CARD8')
+tcard16 = SimpleType(('uint16_t',), 2, 'CARD16')
+tcard32 = SimpleType(('uint32_t',), 4, 'CARD32')
+tcard64 = SimpleType(('uint64_t',), 8, 'CARD64')
+tint8 =  SimpleType(('int8_t',), 1, 'INT8')
+tint16 = SimpleType(('int16_t',), 2, 'INT16')
+tint32 = SimpleType(('int32_t',), 4, 'INT32')
+tint64 = SimpleType(('int64_t',), 8, 'INT64')
+tchar =  SimpleType(('char',), 1, 'char')
+tfloat = SimpleType(('float',), 4, 'float')
+tdouble = SimpleType(('double',), 8, 'double')
+tbyte = SimpleType(('uint8_t',), 1, 'BYTE')
+tbool = SimpleType(('uint8_t',), 1, 'BOOL')
+tvoid = SimpleType(('uint8_t',), 1, 'void')
 
 class FileDescriptor(SimpleType):
     '''
     Derived class which represents a file descriptor.
     '''
     def __init__(self):
-        SimpleType.__init__(self, ('int'), 4)
+        SimpleType.__init__(self, ('int'), 4, 'fd')
         self.is_fd = True
 
     def fixed_size(self):
@@ -240,7 +243,7 @@ class Enum(SimpleType):
     bits contains a list of (name, bitnum) tuples.  items only appear if specified as a bit. bitnum is a number.
     '''
     def __init__(self, name, elt):
-        SimpleType.__init__(self, name, 4)
+        SimpleType.__init__(self, name, 4, 'enum')
         self.values = []
         self.bits = []
         self.doc = None


More information about the xcb-commit mailing list