From: Richard Wiedenhöft Date: Sun, 28 Feb 2016 17:19:29 +0000 (+0100) Subject: Fix broken destruction of null-terminated arrays in async data structs X-Git-Tag: 0.35.1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14cb50afc5e840d0f74f866571df2670d1a3958a;p=thirdparty%2Fvala.git Fix broken destruction of null-terminated arrays in async data structs https://bugzilla.gnome.org/show_bug.cgi?id=762819 --- diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala index 928e67b66..0ab4336d6 100644 --- a/codegen/valagasyncmodule.vala +++ b/codegen/valagasyncmodule.vala @@ -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) { diff --git a/tests/Makefile.am b/tests/Makefile.am index 50d0e230f..363dc29bf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..ea0f1947f --- /dev/null +++ b/tests/asynchronous/bug762819.vala @@ -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 (); +}