From: Rico Tzschichholz Date: Sun, 21 Oct 2018 08:34:28 +0000 (+0200) Subject: girparser: Async methods don't allow out-parameters before in-parameters X-Git-Tag: 0.36.18~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e3ef8856446e037bf60b8ac00b13e34b294272a4;p=thirdparty%2Fvala.git girparser: Async methods don't allow out-parameters before in-parameters 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 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 19514bb69..7172b31fc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..48956f61d --- /dev/null +++ b/tests/gir/async-sync-out.test @@ -0,0 +1,58 @@ +GIR + +Input: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +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; +} diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index c9a9a576d..ca99e3eca 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -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);