Fix glib:error-quark scanning for unregistered enum types
[gnome.gobject-introspection] / giscanner / girwriter.py
index ddd562c..8088628 100644 (file)
@@ -21,9 +21,6 @@
 
 from __future__ import with_statement
 
-import os
-from ctypes.util import find_library
-
 from .ast import (Alias, Array, Bitfield, Callback, Class, Constant, Enum,
                   Function, Interface, List, Map, Member, Struct, Union,
                   Varargs)
@@ -80,16 +77,9 @@ and/or use gtk-doc annotations. ''')
         self.write_tag('c:include', attrs)
 
     def _write_namespace(self, namespace, shlibs, cprefix):
-        libraries = []
-        for l in shlibs:
-            found_libname = find_library(l)
-            if not found_libname:
-                found_libname = l
-            libraries.append(os.path.basename(found_libname))
-
         attrs = [('name', namespace.name),
                  ('version', namespace.version),
-                 ('shared-library', ','.join(libraries)),
+                 ('shared-library', ','.join(shlibs)),
                  ('c:prefix', cprefix)]
         with self.tagcontext('namespace', attrs):
             # We define a custom sorting function here because
@@ -106,7 +96,8 @@ and/or use gtk-doc annotations. ''')
                 else:
                     return cmp(a, b)
             for node in sorted(namespace.nodes, cmp=nscmp):
-                self._write_node(node)
+                if not node.skip:
+                    self._write_node(node)
 
     def _write_node(self, node):
         if isinstance(node, Function):
@@ -161,6 +152,8 @@ and/or use gtk-doc annotations. ''')
         self.write_tag('alias', attrs)
 
     def _write_callable(self, callable, tag_name, extra_attrs):
+        if callable.skip:
+            return
         attrs = [('name', callable.name)]
         attrs.extend(extra_attrs)
         if callable.doc:
@@ -285,10 +278,10 @@ and/or use gtk-doc annotations. ''')
             attrs.extend([('glib:type-name', enum.type_name),
                           ('glib:get-type', enum.get_type),
                           ('c:type', enum.ctype)])
-            if enum.error_quark:
-                attrs.append(('glib:error-quark', enum.error_quark))
         else:
             attrs.append(('c:type', enum.symbol))
+        if hasattr(enum, 'error_quark') and enum.error_quark:
+            attrs.append(('glib:error-quark', enum.error_quark))
 
         with self.tagcontext('enumeration', attrs):
             self._write_attributes(enum)
@@ -313,6 +306,8 @@ and/or use gtk-doc annotations. ''')
                 self._write_member(member)
 
     def _write_member(self, member):
+        if member.skip:
+            return
         attrs = [('name', member.name),
                  ('value', str(member.value)),
                  ('c:identifier', member.symbol)]
@@ -385,6 +380,8 @@ and/or use gtk-doc annotations. ''')
                 self._write_method(method)
 
     def _write_property(self, prop):
+        if prop.skip:
+            return
         attrs = [('name', prop.name)]
         self._append_version(prop, attrs)
         self._append_deprecated(prop, attrs)
@@ -418,6 +415,7 @@ and/or use gtk-doc annotations. ''')
                 ('glib:get-type', boxed.get_type)]
 
     def _write_record(self, record, extra_attrs=[]):
+        is_gtype_struct = False
         attrs = list(extra_attrs)
         if record.name is not None:
             attrs.append(('name', record.name))
@@ -427,6 +425,7 @@ and/or use gtk-doc annotations. ''')
             attrs.append(('disguised', '1'))
         if isinstance(record, GLibRecord):
             if record.is_gtype_struct_for:
+                is_gtype_struct = True
                 attrs.append(('glib:is-gtype-struct-for',
                               record.is_gtype_struct_for))
         if record.doc:
@@ -439,7 +438,7 @@ and/or use gtk-doc annotations. ''')
             self._write_attributes(record)
             if record.fields:
                 for field in record.fields:
-                    self._write_field(field)
+                    self._write_field(field, is_gtype_struct)
             for method in record.constructors:
                 self._write_constructor(method)
             for method in record.methods:
@@ -467,13 +466,20 @@ and/or use gtk-doc annotations. ''')
             for method in union.methods:
                 self._write_method(method)
 
-    def _write_field(self, field):
+    def _write_field(self, field, is_gtype_struct=False):
         if isinstance(field, Function):
             self._write_method(field)
             return
 
         if isinstance(field, Callback):
-            self._write_callback(field)
+            attrs = [('name', field.name)]
+            with self.tagcontext('field', attrs):
+                self._write_attributes(field)
+                if is_gtype_struct:
+                    self._write_callback(field)
+                else:
+                    attrs = [('name', 'any'), ('c:type', 'pointer')]
+                    self.write_tag('type', attrs)
         elif isinstance(field, Struct):
             self._write_record(field)
         elif isinstance(field, Union):
@@ -493,6 +499,8 @@ and/or use gtk-doc annotations. ''')
                 self._write_type(field.type)
 
     def _write_signal(self, signal):
+        if signal.skip:
+            return
         attrs = [('name', signal.name)]
         if signal.doc:
             attrs.append(('doc', signal.doc))