commit 67f55794628dd98db81af5fb0d66353e7dded84d
Author: Matthew Booth <mbooth@redhat.com>
Date:   Mon Mar 5 16:53:40 2012 +0000

    Fix matching of methods named *_get_type()
    
    The code which heuristically turned functions into class methods would always
    ignore any function called *_get_type or *_get_gtype. However, the code which
    looked for GI metadata functions to execute them was much more comprehensive,
    checking not just the name, but also that it had no parameters and that it
    returned a GType.
    
    This change abstracts the more comprehensive check into the Function class, and
    uses the same check in both places.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=671218

diff --git a/giscanner/ast.py b/giscanner/ast.py
index 6df356d..807c0d2 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -589,6 +589,24 @@ class Function(Callable):
         clone.parameters = self.parameters[:]
         return clone
 
+    def is_type_meta_function(self):
+        # Named correctly
+        if not (self.name.endswith('_get_type') or
+                self.name.endswith('_get_gtype')):
+                return False
+
+        # Doesn't have any parameters
+        if self.parameters:
+            return False
+
+        # Returns GType
+        rettype = self.retval.type
+        if (rettype.is_equiv(TYPE_GTYPE) or
+           rettype.target_giname == 'Gtk.Type'):
+            return True
+
+        message.warn("function returns '%r', not a GType" % rettype)
+        return False
 
 class ErrorQuarkFunction(Function):
 
diff --git a/giscanner/gdumpparser.py b/giscanner/gdumpparser.py
index c0c4ef6..c0b13f4 100644
--- a/giscanner/gdumpparser.py
+++ b/giscanner/gdumpparser.py
@@ -188,18 +188,12 @@ blob containing data gleaned from GObject's primitive introspection."""
         if func.symbol == 'g_variant_get_gtype':
             # We handle variants internally, see _initparse_gobject_record
             return True
-        if func.parameters:
-            return False
-        # GType *_get_type(void)
-        rettype = func.retval.type
-        if not (rettype.is_equiv(ast.TYPE_GTYPE)
-                or rettype.target_giname == 'Gtk.Type'):
-            message.warn("function returns '%r', not a GType" % (
-                func.retval.type, ))
-            return False
 
-        self._get_type_functions.append(func.symbol)
-        return True
+        if func.is_type_meta_function():
+            self._get_type_functions.append(func.symbol)
+            return True
+
+        return False
 
     def _initparse_error_quark_function(self, func):
         if (func.retval.type.ctype != 'GQuark'):
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 3a35b0e..7d274b3 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -955,10 +955,11 @@ _split_uscored_by_type(text_buffer_try_new) -> (ast.Class(TextBuffer), 'try_new'
     def _pair_function(self, func):
         """Check to see whether a toplevel function should be a
 method or constructor of some type."""
-        if (func.symbol.endswith('_get_type')
-            or func.symbol.endswith('_get_gtype')
-            or func.symbol.startswith('_')):
+
+        # Ignore internal symbols and type metadata functions
+        if func.symbol.startswith('_') or func.is_type_meta_function():
             return
+
         (ns, subsymbol) = self._transformer.split_csymbol(func.symbol)
         assert ns == self._namespace
         if self._is_constructor(func, subsymbol):
