]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix broken destruction of null-terminated arrays in async data structs
authorRichard Wiedenhöft <richard@wiedenhoeft.xyz>
Sun, 28 Feb 2016 17:19:29 +0000 (18:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 7 Nov 2016 13:34:01 +0000 (14:34 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=762819

codegen/valagasyncmodule.vala
tests/Makefile.am
tests/asynchronous/bug762819.vala [new file with mode: 0644]

index 928e67b6635521a279120965afd56312aaa7d994..0ab4336d6d99b821b85b768c88d60bc05c72adfb 100644 (file)
@@ -123,9 +123,15 @@ public class Vala.GAsyncModule : GtkModule {
                }
 
                if (requires_destroy (m.return_type)) {
-                       /* this is very evil. */
-                       var v = new LocalVariable (m.return_type, ".result");
-                       ccode.add_expression (destroy_local (v));
+                       if (get_ccode_array_length (m) || !(m.return_type is ArrayType)) {
+                               /* this is very evil. */
+                               var v = new LocalVariable (m.return_type, ".result");
+                               ccode.add_expression (destroy_local (v));
+                       } else {
+                               var v = new GLibValue (m.return_type, new CCodeIdentifier ("_data_->result"), true);
+                               v.array_null_terminated = get_ccode_array_null_terminated (m);
+                               ccode.add_expression (destroy_value (v));
+                       }
                }
 
                if (m.binding == MemberBinding.INSTANCE) {
index 50d0e230fc3cb85eb1b3869eb73fd5b46f1fc53e..363dc29bf6dc66d9d4f6c02b649c7314ed634303 100644 (file)
@@ -222,6 +222,7 @@ TESTS = \
        asynchronous/bug659886.vala \
        asynchronous/bug661961.vala \
        asynchronous/bug742621.vala \
+       asynchronous/bug762819.vala \
        asynchronous/closures.vala \
        asynchronous/generator.vala \
        asynchronous/yield.vala \
diff --git a/tests/asynchronous/bug762819.vala b/tests/asynchronous/bug762819.vala
new file mode 100644 (file)
index 0000000..ea0f194
--- /dev/null
@@ -0,0 +1,22 @@
+abstract class Bar : GLib.Object {
+       [CCode (array_length = false, array_null_terminated = true)]
+       public abstract async string[] get_string_async ();
+}
+
+class Foo : Bar {
+       public override async string[] get_string_async () {
+               return { "foo", "bar" };
+       }
+}
+
+void main () {
+       var loop = new MainLoop ();
+       var foo = new Foo ();
+       foo.get_string_async.begin ((obj, res) => {
+               var result = foo.get_string_async.end (res);
+               assert (result.length == 2);
+               assert (result[1] == "bar");
+               loop.quit ();
+       });
+       loop.run ();
+}