def _enum_common_prefix(self, symbol):
def common_prefix(a, b):
- alen = len(a)
- blen = len(b)
- l = min(alen, blen)
- for i in xrange(l):
- if a[i] != b[i]:
- return a[:i]
- if alen > blen:
- return b
- return a
+ commonparts = []
+ for aword, bword in zip(a.split('_'), b.split('_')):
+ if aword != bword:
+ return '_'.join(commonparts) + '_'
+ commonparts.append(aword)
+ return min(a, b)
+
# Nothing less than 2 has a common prefix
if len(list(symbol.base_type.child_list)) < 2:
return None
symbol.ident)
def _type_is_callback(self, type):
- if (isinstance(type, Callback) or
- isinstance(self._typedefs_ns.get(type.name), Callback)):
+ if isinstance(type, Callback):
+ return True
+ node = self._names.names.get(type.name)
+ if node and isinstance(node[1], Callback):
return True
return False
return False
def _handle_destroy(self, param, destroy_idx, destroy_param):
- if ((self._namespace.name == 'GLib' and
- destroy_param.type.name == 'DestroyNotify') or
- destroy_param.type.name == 'GLib.DestroyNotify'):
+ if (destroy_param.type.name == 'GLib.DestroyNotify' or
+ destroy_param.type.ctype == 'GDestroyNotify'):
param.destroy_name = destroy_param.name
param.destroy_index = destroy_idx
return True
if not self._type_is_callback(param.type):
continue
+ # set a default scope
+ if param.scope is None:
+ param.scope = 'call'
+
# j is the index where we look for closure/destroy to
# group with the callback param
j = i + 1