]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
GAsync: Fix capturing parameters in async methods
authorJürg Billeter <j@bitron.ch>
Thu, 20 Jan 2011 12:38:15 +0000 (13:38 +0100)
committerJürg Billeter <j@bitron.ch>
Thu, 20 Jan 2011 13:41:04 +0000 (14:41 +0100)
codegen/valagasyncmodule.vala
tests/asynchronous/closures.vala

index d4ce037ab2b893527e92d6a8becb50673f132fa6..997181793e3cf55fb4f114bd7e3398934925cee4 100644 (file)
@@ -107,7 +107,13 @@ public class Vala.GAsyncModule : GSignalModule {
                                param_type.value_owned = true;
 
                                if (requires_destroy (param_type) && !is_unowned_delegate) {
+                                       // do not try to access closure blocks
+                                       bool old_captured = param.captured;
+                                       param.captured = false;
+
                                        freeblock.add_statement (new CCodeExpressionStatement (get_unref_expression_ (param)));
+
+                                       param.captured = old_captured;
                                }
                        }
                }
index 79b020a19064ae087ebfcfd272c5623f2b326b2e..791010c924882df7361761460c79c2822dcc52a2 100644 (file)
@@ -2,10 +2,10 @@ delegate void Func ();
 
 MainLoop main_loop;
 
-async void foo () {
+async void foo (string baz) {
        string bar = "hello";
        Func foobar = () => {
-               bar = "world";
+               bar = baz;
        };
        foobar ();
        assert (bar == "world");
@@ -17,7 +17,7 @@ async void foo () {
 }
 
 void main () {
-       foo.begin ();
+       foo.begin ("world");
 
         main_loop = new MainLoop (null, false);
         main_loop.run ();