[gobject-introspection] scanner: allow for functions that look like constructors but aren't



commit 44cf78baf6496835abbf3c092895c2a46a2d4ef0
Author: Dan Winship <danw gnome org>
Date:   Sat May 26 20:19:39 2012 -0400

    scanner: allow for functions that look like constructors but aren't
    
    If the scanner found a function with _new in its name, but not
    prefixed by the name of a known type, it would assume that the
    function was a constructor, and then complain that it couldn't figure
    out what it was a constructor for, and mark it introspectable=0.
    
    Instead, just assume that the function is not actually a constructor
    in that case (unless it's explicitly tagged as such).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676815

 giscanner/maintransformer.py       |    7 ++++---
 tests/scanner/Foo-1.0-expected.gir |    8 ++++++++
 tests/scanner/foo.c                |   14 ++++++++++++++
 tests/scanner/foo.h                |    2 ++
 4 files changed, 28 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 60c5bc4..bb10c99 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -1147,9 +1147,10 @@ method or constructor of some type."""
 
         origin_node = self._get_constructor_class(func, subsymbol)
         if origin_node is None:
-            message.warn_node(func,
-                "Can't find matching type for constructor; symbol=%r" \
-                % (func.symbol, ))
+            if func.is_constructor:
+                message.warn_node(func,
+                    "Can't find matching type for constructor; symbol=%r" \
+                    % (func.symbol, ))
             return False
 
         # Some sanity checks; only objects and boxeds can have ctors
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index 15be459..b18375a 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -1054,6 +1054,14 @@ exposed to language bindings.</doc>
         </parameter>
       </parameters>
     </function>
+    <function name="not_a_constructor_new"
+              c:identifier="foo_not_a_constructor_new">
+      <doc xml:whitespace="preserve">This should be scanned as a top-level function, and shouldn't cause
+a "Can't find matching type for constructor" warning.</doc>
+      <return-value transfer-ownership="none">
+        <type name="Object" c:type="FooObject*"/>
+      </return-value>
+    </function>
     <function name="rectangle_new"
               c:identifier="foo_rectangle_new"
               moved-to="Rectangle.new"
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index fb20c7a..f8cc350 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -782,3 +782,17 @@ foo_object_append_new_stack_layer (FooObject *obj, int x)
 {
   return NULL;
 }
+
+/**
+ * foo_not_a_constructor_new:
+ *
+ * This should be scanned as a top-level function, and shouldn't cause
+ * a "Can't find matching type for constructor" warning.
+ *
+ * Returns: (transfer none):
+ */
+FooObject *
+foo_not_a_constructor_new (void)
+{
+  return NULL;
+}
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index 270ee21..f852083 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -162,6 +162,8 @@ void                  foo_buffer_some_method       (FooBuffer *buffer);
 
 GType                 foo_other_object_get_type    (void) G_GNUC_CONST;
 
+FooObject *           foo_not_a_constructor_new    (void);
+
 typedef enum
 {
   FOO_ENUM_ALPHA,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]