[gobject-introspection] Foreign structs can have constructors



commit a9dc0722ae291fc0644cebc9f2ec3bb61b0d9d87
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Thu Sep 9 16:33:25 2010 +0200

    Foreign structs can have constructors

 giscanner/maintransformer.py       |    4 ++--
 tests/scanner/Foo-1.0-expected.gir |    5 +++++
 tests/scanner/foo.c                |    6 ++++++
 tests/scanner/foo.h                |    2 ++
 4 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 4a9c952..a60b9bb 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -822,7 +822,7 @@ method or constructor of some type."""
         target = self._transformer.lookup_typenode(func.retval.type)
         if not (isinstance(target, ast.Class)
                 or (isinstance(target, (ast.Record, ast.Union, ast.Boxed))
-                    and target.get_type is not None)):
+                    and (target.get_type is not None or target.foreign))):
             return False
 
         split = self._split_uscored_by_type(subsymbol)
@@ -835,7 +835,7 @@ method or constructor of some type."""
         # Some sanity checks; only objects and boxeds can have ctors
         if not (isinstance(origin_node, ast.Class)
                 or (isinstance(origin_node, (ast.Record, ast.Union, ast.Boxed))
-                    and origin_node.get_type is not None)):
+                    and (origin_node.get_type is not None or origin_node.foreign))):
             return False
         # Verify the namespace - don't want to append to foreign namespaces!
         if origin_node.namespace != self._namespace:
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index 36bec03..a0cb696 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -255,6 +255,11 @@ and/or use gtk-doc annotations.  -->
       <field name="foo" writable="1">
         <type name="gint" c:type="int"/>
       </field>
+      <constructor name="new" c:identifier="foo_foreign_struct_new">
+        <return-value transfer-ownership="full">
+          <type name="ForeignStruct" c:type="FooForeignStruct*"/>
+        </return-value>
+      </constructor>
     </record>
     <interface name="Interface"
                c:symbol-prefix="interface"
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index 9e3a38d..a2901f1 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -711,6 +711,12 @@ foo_skip_me (FooSkippable fs)
  *
  */
 
+FooForeignStruct*
+foo_foreign_struct_new (void)
+{
+  return g_slice_new0 (FooForeignStruct);
+}
+
 /**
  * foo_test_varargs_callback: (skip)
  *
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index 110c313..6c57266 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -423,6 +423,8 @@ struct _FooForeignStruct
   int foo;
 };
 
+FooForeignStruct* foo_foreign_struct_new (void);
+
 /* This one should be a global, not a method on UtilityObject since
  * it's a separate namespace.
  */



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