Fix glib:error-quark scanning for unregistered enum types
[gnome.gobject-introspection] / giscanner / transformer.py
index a131e3c..bbcabe4 100644 (file)
@@ -19,6 +19,7 @@
 #
 
 import os
+import sys
 
 from .ast import (Bitfield, Callback, Enum, Function, Namespace, Member,
                   Parameter, Return, Struct, Field,
@@ -125,8 +126,9 @@ class Transformer(object):
             path = os.path.join(d, girname)
             if os.path.exists(path):
                 return path
-        raise ValueError("Couldn't find include %r (search path: %r)"\
+        sys.stderr.write("Couldn't find include %r (search path: %r)\n"\
                          % (girname, searchdirs))
+        sys.exit(1)
 
     def _parse_include(self, filename):
         parser = self._cachestore.load(filename)
@@ -267,8 +269,10 @@ class Transformer(object):
                       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
 
@@ -281,9 +285,8 @@ class Transformer(object):
         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
@@ -294,6 +297,10 @@ class Transformer(object):
             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
@@ -685,3 +692,8 @@ class Transformer(object):
             else:
                 break
         return type_name
+
+    def iter_enums(self):
+        for node in self._namespace.nodes:
+            if isinstance(node, Enum):
+                yield node