]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
girparser: Async methods don't allow out-parameters before in-parameters
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 21 Oct 2018 08:34:28 +0000 (10:34 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 28 Feb 2019 17:25:40 +0000 (18:25 +0100)
In vala out-parameters are always handled in the *_finish implementation
and therefore are asynchronous. Report a warning for GIR sources where
convert them to pointer-types to create usuable signatures for bindings.

See https://gitlab.gnome.org/GNOME/vala/issues/636

tests/Makefile.am
tests/gir/async-sync-out.test [new file with mode: 0644]
vala/valagirparser.vala

index 19514bb690d541f96a72f1a2c0dbc2fd72dd59fc..7172b31fcad8a78388ea818a31394d87aaa8370e 100644 (file)
@@ -374,6 +374,7 @@ TESTS = \
        gir/bug788775.test \
        gir/array-fixed-length.test \
        gir/async-result-pos.test \
+       gir/async-sync-out.test \
        gir/delegate-alias-without-target.test \
        annotations/deprecated.vala \
        annotations/description.vala \
diff --git a/tests/gir/async-sync-out.test b/tests/gir/async-sync-out.test
new file mode 100644 (file)
index 0000000..48956f6
--- /dev/null
@@ -0,0 +1,58 @@
+GIR
+
+Input:
+
+<class name="Foo" c:type="TestFoo" glib:type-name="TestFoo" glib:get-type="test_foo_get_type" glib:type-struct="FooClass" parent="GObject.Object">
+  <method name="method_async" c:identifier="test_foo_method_async">
+    <return-value transfer-ownership="none">
+      <type name="none"/>
+    </return-value>
+    <parameters>
+      <instance-parameter name="self" transfer-ownership="none">
+        <type name="Foo" c:type="TestFoo*"/>
+      </instance-parameter>
+      <parameter name="input" transfer-ownership="none">
+        <type name="utf8" c:type="const gchar*"/>
+      </parameter>
+      <parameter name="sync_output" direction="out" transfer-ownership="full">
+        <type name="utf8" c:type="gchar**"/>
+      </parameter>
+      <parameter name="_callback_" transfer-ownership="none" allow-none="1" closure="3" scope="async">
+        <type name="Gio.AsyncReadyCallback" c:type="GAsyncReadyCallback"/>
+      </parameter>
+      <parameter name="_callback__target" transfer-ownership="none" allow-none="1">
+        <type name="gpointer" c:type="void*"/>
+      </parameter>
+    </parameters>
+  </method>
+  <method name="method_finish" c:identifier="test_foo_method_finish" throws="1">
+    <return-value transfer-ownership="full">
+      <type name="none"/>
+    </return-value>
+    <parameters>
+      <instance-parameter name="self" transfer-ownership="none">
+        <type name="Foo" c:type="TestFoo*"/>
+      </instance-parameter>
+      <parameter name="_res_" transfer-ownership="none">
+        <type name="Gio.AsyncResult" c:type="GAsyncResult*"/>
+      </parameter>
+      <parameter name="output" direction="out" transfer-ownership="full">
+        <type name="utf8" c:type="gchar**"/>
+      </parameter>
+    </parameters>
+  </method>
+  <constructor name="new" c:identifier="test_foo_new">
+    <return-value transfer-ownership="full">
+      <type name="Test.Foo" c:type="TestFoo*"/>
+    </return-value>
+  </constructor>
+</class>
+
+Output:
+
+[CCode (cheader_filename = "test.h", type_id = "test_foo_get_type ()")]
+public class Foo : GLib.Object {
+       [CCode (has_construct_function = false)]
+       public Foo ();
+       public async void method_async (string input, string* sync_output, out string output) throws GLib.Error;
+}
index c9a9a576d749beccf24763108209f8e803cf5524..ca99e3ecaec3baf3c2e5a7f415db34f110b53856 100644 (file)
@@ -4042,6 +4042,20 @@ public class Vala.GirParser : CodeVisitor {
 
        void process_async_method (Node node) {
                var m = (Method) node.symbol;
+
+               // TODO: async methods with out-parameters before in-parameters are not supported
+               bool requires_pointer = false;
+               foreach (var param in m.get_parameters ()) {
+                       if (param.direction == ParameterDirection.IN) {
+                               requires_pointer = true;
+                       } else if (requires_pointer) {
+                               param.direction = ParameterDirection.IN;
+                               param.variable_type.nullable = false;
+                               param.variable_type = new PointerType (param.variable_type);
+                               Report.warning (param.source_reference, "Synchronous out-parameters are not supported in async methods");
+                       }
+               }
+
                string finish_method_base;
                if (m.name == null) {
                        assert (m is CreationMethod);