Avoid name collisions between xidtype and enum.
authorPeter Harris <pharris@opentext.com>
Fri, 13 Mar 2009 19:24:55 +0000 (15:24 -0400)
committerPeter Harris <peter.harris@hummingbird.com>
Sat, 14 Mar 2009 16:34:31 +0000 (12:34 -0400)
These changes are necessary to build with latest xcb/proto.

Signed-off-by: Peter Harris <pharris@opentext.com>
src/c_client.py

index 73bd064..d86d05e 100755 (executable)
@@ -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):
     '''