[PATCH 2/3] Avoid name collisions between xidtype and enum.

Peter Harris pharris at opentext.com
Fri Mar 13 12:24:55 PDT 2009


These changes are necessary to build with latest xcb/proto.

Signed-off-by: Peter Harris <pharris at opentext.com>
---
 src/c_client.py |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/c_client.py b/src/c_client.py
index 73bd064..e283b4a 100755
--- a/src/c_client.py
+++ b/src/c_client.py
@@ -125,6 +125,21 @@ def _t(list):
         parts = [list[0]] + [_n_item(i) for i in list[1:]] + ['t']
     return '_'.join(parts).lower()
         
+def _enum(list):
+    '''
+    Does C-name conversion on a tuple of strings representing a type.
+    Same as _n but adds a "_enum_t" on the end.
+    '''
+    if len(list) == 1:
+        parts = list
+    elif len(list) == 2:
+        parts = [list[0], _n_item(list[1]), 'enum', 't']
+    elif _ns.is_ext:
+        parts = [list[0], _ext(list[1])] + [_n_item(i) for i in list[2:]] + ['enum', 't']
+    else:
+        parts = [list[0]] + [_n_item(i) for i in list[1:]] + ['enum', 't']
+    return '_'.join(parts).lower()
+
 
 def c_open(self):
     '''
@@ -135,6 +150,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 +234,26 @@ def c_close(self):
             cfile.write('\n')
     cfile.close()
 
+def build_collision_table():
+    global namecount
+    namecount = {}
+
+    for k, v in module.types.items():
+        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 = _enum(name)
+
     _h_setlevel(0)
     _h('')
-    _h('typedef enum %s {', _t(name))
+    _h('typedef enum %s {', tname)
 
     count = len(self.values)
 
@@ -232,7 +263,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):
     '''
-- 
1.6.2


--------------070208020100080806030604--


More information about the Xcb mailing list