]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Fix copying struct parameters for lambdas and async methods.
authorLuca Bruno <lethalman88@gmail.com>
Wed, 23 Jun 2010 16:54:22 +0000 (18:54 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 23 Jun 2010 21:07:53 +0000 (23:07 +0200)
Fixes bug 622422.

codegen/valaccodebasemodule.vala
codegen/valagasyncmodule.vala
tests/Makefile.am
tests/asynchronous/bug613484.vala
tests/structs/bug622422.vala [new file with mode: 0644]

index 41c6a59e5d2691c111c412a00b91c68f55853d96..031c5d2f955e31a9275b1144a155e65317dc4d83 100644 (file)
@@ -1637,6 +1637,9 @@ public class Vala.CCodeBaseModule : CCodeModule {
 
                // create copy if necessary as captured variables may need to be kept alive
                CCodeExpression cparam = get_variable_cexpression (param.name);
+               if (param.parameter_type.is_real_non_null_struct_type ()) {
+                       cparam = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cparam);
+               }
                if (requires_copy (param_type) && !param.parameter_type.value_owned && !is_unowned_delegate)  {
                        var ma = new MemberAccess.simple (param.name);
                        ma.symbol_reference = param;
index 508bac56528bdfa32ac2e6e25e2017a0287bb46f..32679f0630f5d400232863e49e0338d240b68b45 100644 (file)
@@ -230,12 +230,13 @@ public class Vala.GAsyncModule : GSignalModule {
 
                                // create copy if necessary as variables in async methods may need to be kept alive
                                CCodeExpression cparam = get_variable_cexpression (param.name);
+                               if (param.parameter_type.is_real_non_null_struct_type ()) {
+                                       cparam = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cparam);
+                               }
                                if (requires_copy (param_type) && !param.parameter_type.value_owned)  {
                                        var ma = new MemberAccess.simple (param.name);
                                        ma.symbol_reference = param;
                                        cparam = get_ref_cexpression (param.parameter_type, cparam, ma, param);
-                               } else if (param.parameter_type.is_real_non_null_struct_type ()) {
-                                       cparam = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, cparam);
                                }
 
                                asyncblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeMemberAccess.pointer (data_var, get_variable_cname (param.name)), cparam)));
index 31616581a4347d05f4134e699e17fc75f9ca5dfc..236e316ba79c68e33bd9d1d5f85468b1418bd0af 100644 (file)
@@ -47,6 +47,7 @@ TESTS = \
        structs/bug606202.vala \
        structs/bug613513.vala \
        structs/bug613825.vala \
+       structs/bug622422.vala \
        delegates/delegates.vala \
        delegates/bug595610.vala \
        delegates/bug595639.vala \
index 581686f62557c1509c2b959c235fcfd3ed8de00b..a4367e126b6e95abb975afb6f67553721008c80e 100644 (file)
@@ -2,10 +2,10 @@ struct Foo {
        int i;
 }
 
-void do_foo (Foo foo) {
+void do_foo (Foo foo, Value value) {
 }
 
-async void do_foo_async (Foo foo) {
+async void do_foo_async (Foo foo, Value value) {
 }
 
 void main () {
diff --git a/tests/structs/bug622422.vala b/tests/structs/bug622422.vala
new file mode 100644 (file)
index 0000000..da761d4
--- /dev/null
@@ -0,0 +1,15 @@
+struct Foo {
+       int i;
+}
+
+delegate void TestDelegate ();
+
+void do_foo (TestDelegate d) {
+}
+
+void do_foo_lambda (Foo foo, Value value) {
+       do_foo (() => { foo.i = 1; value = (int) 2; });
+}
+
+void main () {
+}