[vala] codegen: Use store_value when assigning the new value to out arguments



commit 1e1db0c52f7ee2cf8b45097c78e6d22334d658e3
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun May 15 15:19:09 2011 +0200

    codegen: Use store_value when assigning the new value to out arguments
    
    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 |   19 +++----------------
 tests/objects/methods.vala             |   10 ++++++++++
 2 files changed, 13 insertions(+), 16 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index eb03b41..4f8ce16 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -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));
 		}
 	}
 
diff --git a/tests/objects/methods.vala b/tests/objects/methods.vala
index 64fd4f0..7217474 100644
--- a/tests/objects/methods.vala
+++ b/tests/objects/methods.vala
@@ -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");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]