[Xcb-commit] 2 commits - src
Peter Harris
peterh at kemper.freedesktop.org
Sat Mar 14 12:51:58 PDT 2009
src/c_client.py | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
New commits:
commit eaa71eac02c6a862ab23e8afcce12d9f38590338
Author: Peter Harris <pharris at opentext.com>
Date: Fri Mar 13 15:24:55 2009 -0400
Avoid name collisions between xidtype and enum.
These changes are necessary to build with latest xcb/proto.
Signed-off-by: Peter Harris <pharris at opentext.com>
diff --git a/src/c_client.py b/src/c_client.py
index 73bd064..d86d05e 100755
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -135,6 +135,9 @@ def c_open(self):
_ns = self.namespace
_ns.c_ext_global_name = _n(_ns.prefix + ('id',))
+ # Build the type-name collision avoidance table used by c_enum
+ build_collision_table()
+
_h_setlevel(0)
_c_setlevel(0)
@@ -216,13 +219,26 @@ def c_close(self):
cfile.write('\n')
cfile.close()
+def build_collision_table():
+ global namecount
+ namecount = {}
+
+ for v in module.types.values():
+ name = _t(v[0])
+ namecount[name] = (namecount.get(name) or 0) + 1
+
def c_enum(self, name):
'''
Exported function that handles enum declarations.
'''
+
+ tname = _t(name)
+ if namecount[tname] > 1:
+ tname = _t(name + ('enum',))
+
_h_setlevel(0)
_h('')
- _h('typedef enum %s {', _t(name))
+ _h('typedef enum %s {', tname)
count = len(self.values)
@@ -232,7 +248,7 @@ def c_enum(self, name):
comma = ',' if count > 0 else ''
_h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
- _h('} %s;', _t(name))
+ _h('} %s;', tname)
def _c_type_setup(self, name, postfix):
'''
commit e986d1ee5a126dc38113125075a1e986235ba7c7
Author: Peter Harris <pharris at opentext.com>
Date: Fri Mar 13 15:25:30 2009 -0400
Revert "Don't use enums in generated C code"
This commit broke xcb/util.
This reverts commit 9984b72888108a038d6b3f7dee374d17e26ef9e2.
Signed-off-by: Peter Harris <pharris at opentext.com>
diff --git a/src/c_client.py b/src/c_client.py
index 299ad54..73bd064 100755
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -222,15 +222,17 @@ def c_enum(self, name):
'''
_h_setlevel(0)
_h('')
+ _h('typedef enum %s {', _t(name))
- next = -1
+ count = len(self.values)
for (enam, eval) in self.values:
- if eval == '':
- next += 1
- else:
- next = int(eval)
- _h('static const uint32_t %s = %d;', _n(name + (enam,)).upper(), next)
+ count = count - 1
+ equals = ' = ' if eval != '' else ''
+ comma = ',' if count > 0 else ''
+ _h(' %s%s%s%s', _n(name + (enam,)).upper(), equals, eval, comma)
+
+ _h('} %s;', _t(name))
def _c_type_setup(self, name, postfix):
'''
More information about the xcb-commit
mailing list