]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use store_value when assigning the new value to out arguments
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 15 May 2011 13:19:09 +0000 (15:19 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Sun, 15 May 2011 13:56:15 +0000 (15:56 +0200)
This fixes:
 * Assigning the _size variable for arrays (was missing)
 * Assigning the delegate destroy notify (was missing)
 * Array parameters with no length (crashed the compiler)

codegen/valaccodemethodcallmodule.vala
tests/objects/methods.vala

index eb03b41783646f48ebd57c125815a3305ea9dab3..4f8ce1611bed2491dfd6abbc38358b05878c3d22 100644 (file)
@@ -392,6 +392,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                var temp_var = get_temp_variable (param.variable_type, param.variable_type.value_owned);
                                                emit_temp_var (temp_var);
                                                set_cvalue (arg, get_variable_cexpression (temp_var.name));
+                                               arg.target_value.value_type = arg.target_type;
 
                                                cexpr = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_cvalue (arg));
 
@@ -773,27 +774,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                continue;
                        }
 
-                       if (requires_destroy (arg.value_type)) {
+                       if (requires_destroy (unary.inner.value_type)) {
                                // unref old value
                                ccode.add_expression (destroy_value (unary.inner.target_value));
                        }
 
                        // assign new value
-                       var value = ((GLibValue) unary.target_value).copy ();
-                       value.value_type = unary.target_type;
-                       ccode.add_assignment (get_cvalue (unary.inner), get_cvalue_ (transform_value (value, unary.inner.value_type, arg)));
-
-                       var array_type = arg.value_type as ArrayType;
-                       if (array_type != null) {
-                               for (int dim = 1; dim <= array_type.rank; dim++) {
-                                       ccode.add_assignment (get_array_lengths (unary.inner).get (dim - 1), get_array_lengths (unary).get (dim - 1));
-                               }
-                       }
-
-                       var delegate_type = arg.value_type as DelegateType;
-                       if (delegate_type != null) {
-                               ccode.add_assignment (get_delegate_target (unary.inner), get_delegate_target (unary));
-                       }
+                       store_value (unary.inner.target_value, transform_value (unary.target_value, unary.inner.value_type, arg));
                }
        }
 
index 64fd4f0dea2f1e7b651d2d1fe46b4a8d1036737e..7217474ca0af69551b19d7a555cd4b17e80eb667 100644 (file)
@@ -62,6 +62,7 @@ class Maman.SubBar : Bar {
 
                string str, str2;
                weak string weak_str;
+               string[] array;
 
                test_out (out str);
                assert (str == "hello");
@@ -78,6 +79,11 @@ class Maman.SubBar : Bar {
                test_ref_weak (ref weak_str);
                assert (weak_str == "world");
 
+               test_out_array_no_length (out array);
+               assert (array[0] == "hello");
+               assert (array[1] == "world");
+               assert (array.length < 0);
+
                ClassTest.run_test ();
 
                return 0;
@@ -182,6 +188,10 @@ void test_ref_weak (ref weak string bar) {
        bar = "world";
 }
 
+void test_out_array_no_length ([CCode (array_length = false)] out string[] bar) {
+       bar = {"hello", "world"};
+}
+
 class Maman.ClassTest {
        public class void class_method () {
                stdout.printf(" OK\n");