scanner: methods cannot have an out-arg as their first arg
authorTorsten Schönfeld <kaffeetisch@gmx.de>
Fri, 17 Aug 2012 22:27:21 +0000 (00:27 +0200)
committerTorsten Schönfeld <kaffeetisch@gmx.de>
Tue, 21 Aug 2012 18:52:03 +0000 (20:52 +0200)
This ensures that if the first argument of a function like

  gboolean gdk_rgba_parse (GdkRGBA *rgba, const gchar *spec);

is annotated as being an out-arg, the result is a class function with two
arguments, not a method with one argument.  Previously, the (out) annotation
was simply ignored.

https://bugzilla.gnome.org/show_bug.cgi?id=682124

giscanner/maintransformer.py
tests/scanner/Regress-1.0-expected.gir
tests/scanner/regress.c
tests/scanner/regress.h

index 77a66d21fdd1b3730e74547efe3312cc34d3d72f..d4163fae2b1bad2cdb93b66b376c5eab0460c40e 100644 (file)
@@ -1001,6 +1001,12 @@ method or constructor of some type."""
                     '%s: Methods must belong to the same namespace as the '
                     'class they belong to' % (func.symbol, ))
             return False
+        if first.direction == ast.PARAM_DIRECTION_OUT:
+            if func.is_method:
+                message.warn_node(func,
+                    '%s: The first argument of methods cannot be an '
+                    'out-argument' % (func.symbol, ))
+            return False
 
         # A quick hack here...in the future we should catch C signature/GI signature
         # mismatches in a general way in finaltransformer
index e954705b664e3a82150a9e34997a67263f5852ec..1d826766fad99ab112d340df24129b9bf598c759 100644 (file)
@@ -1444,6 +1444,24 @@ Use with regress_test_obj_emit_sig_with_obj</doc>
           </parameter>
         </parameters>
       </method>
+      <function name="parse" c:identifier="regress_test_struct_a_parse">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="a_out"
+                     direction="out"
+                     caller-allocates="1"
+                     transfer-ownership="none">
+            <doc xml:whitespace="preserve">the structure that is to be filled</doc>
+            <type name="TestStructA" c:type="RegressTestStructA*"/>
+          </parameter>
+          <parameter name="string" transfer-ownership="none">
+            <doc xml:whitespace="preserve">ignored</doc>
+            <type name="utf8" c:type="const gchar*"/>
+          </parameter>
+        </parameters>
+      </function>
     </record>
     <record name="TestStructB" c:type="RegressTestStructB">
       <field name="some_int8" writable="1">
@@ -3059,6 +3077,26 @@ What we're testing here is that the scanner ignores the @a nested inside XML.</d
         </parameter>
       </parameters>
     </function>
+    <function name="test_struct_a_parse"
+              c:identifier="regress_test_struct_a_parse"
+              moved-to="TestStructA.parse">
+      <return-value transfer-ownership="none">
+        <type name="none" c:type="void"/>
+      </return-value>
+      <parameters>
+        <parameter name="a_out"
+                   direction="out"
+                   caller-allocates="1"
+                   transfer-ownership="none">
+          <doc xml:whitespace="preserve">the structure that is to be filled</doc>
+          <type name="TestStructA" c:type="RegressTestStructA*"/>
+        </parameter>
+        <parameter name="string" transfer-ownership="none">
+          <doc xml:whitespace="preserve">ignored</doc>
+          <type name="utf8" c:type="const gchar*"/>
+        </parameter>
+      </parameters>
+    </function>
     <function name="test_strv_in" c:identifier="regress_test_strv_in">
       <return-value transfer-ownership="none">
         <type name="gboolean" c:type="gboolean"/>
index 910f01a5a174fb8c4f96758fbaff6024ec8727a7..e72c5aa738c97e1eacda26ca2d328df02eac75e8 100644 (file)
@@ -1672,6 +1672,18 @@ regress_test_struct_a_clone (RegressTestStructA *a,
   *a_out = *a;
 }
 
+/**
+ * regress_test_struct_a_parse:
+ * @a_out: (out caller-allocates): the structure that is to be filled
+ * @string: ignored
+ */
+void
+regress_test_struct_a_parse (RegressTestStructA *a_out,
+                             const gchar *string)
+{
+       a_out->some_int = 23;
+}
+
 /**
  * regress_test_struct_b_clone:
  * @b: the structure
index d6bdacb2df6a2f121ec5a8064785623cfb99fbe5..949a3764143442d99c767956a799e91e857add35 100644 (file)
@@ -282,6 +282,7 @@ struct _RegressTestStructA
 
 void regress_test_struct_a_clone (RegressTestStructA *a,
                                  RegressTestStructA *a_out);
+void regress_test_struct_a_parse (RegressTestStructA *a_out, const gchar *string);
 
 struct _RegressTestStructB
 {