vala r1073 - in trunk: . gobject tests



Author: juergbi
Date: Sat Mar  1 10:39:41 2008
New Revision: 1073
URL: http://svn.gnome.org/viewvc/vala?rev=1073&view=rev

Log:
2008-03-01  Juerg Billeter  <j bitron ch>

	* gobject/valaccodegeneratorinvocationexpression.vala: fix argument
	  dependency in the C code for array and delegate arguments,
	  fixes bug 519597

	* tests/arrays.vala: test array argument


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodegeneratorinvocationexpression.vala
   trunk/tests/arrays.vala

Modified: trunk/gobject/valaccodegeneratorinvocationexpression.vala
==============================================================================
--- trunk/gobject/valaccodegeneratorinvocationexpression.vala	(original)
+++ trunk/gobject/valaccodegeneratorinvocationexpression.vala	Sat Mar  1 10:39:41 2008
@@ -227,16 +227,25 @@
 				var param = params_it.get ();
 				ellipsis = param.ellipsis;
 				if (!ellipsis) {
+					// if the vala argument expands to multiple C arguments,
+					// we have to make sure that the C arguments don't depend
+					// on each other as there is no guaranteed argument
+					// evaluation order
+					// http://bugzilla.gnome.org/show_bug.cgi?id=519597
+					bool multiple_cargs = false;
+
 					if (!param.no_array_length && param.type_reference is ArrayType) {
 						var array_type = (ArrayType) param.type_reference;
 						for (int dim = 1; dim <= array_type.rank; dim++) {
 							carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_array_length_cexpression (arg, dim));
 						}
+						multiple_cargs = true;
 					} else if (param.type_reference is DelegateType) {
 						var deleg_type = (DelegateType) param.type_reference;
 						var d = deleg_type.delegate_symbol;
 						if (d.instance) {
 							carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_delegate_target_cexpression (arg));
+							multiple_cargs = true;
 						}
 					}
 					cexpr = get_implicit_cast_expression (cexpr, arg.static_type, param.type_reference);
@@ -249,6 +258,25 @@
 						}
 					}
 
+					if (multiple_cargs && arg is InvocationExpression) {
+						// if vala argument is invocation expression
+						// the auxiliary C argument(s) will depend on the main C argument
+
+						// (tmp = arg1, call (tmp, arg2, arg3,...))
+
+						var ccomma = new CCodeCommaExpression ();
+
+						var temp_decl = get_temp_variable_declarator (arg.static_type);
+						temp_vars.insert (0, temp_decl);
+						ccomma.append_expression (new CCodeAssignment (new CCodeIdentifier (temp_decl.name), cexpr));
+
+						cexpr = new CCodeIdentifier (temp_decl.name);
+
+						ccomma.append_expression (ccall_expr);
+
+						ccall_expr = ccomma;
+					}
+
 					// unref old value for non-null non-weak out arguments
 					if (param.type_reference.is_out && param.type_reference.takes_ownership && !(arg.static_type is NullType)) {
 						var unary = (UnaryExpression) arg;

Modified: trunk/tests/arrays.vala
==============================================================================
--- trunk/tests/arrays.vala	(original)
+++ trunk/tests/arrays.vala	Sat Mar  1 10:39:41 2008
@@ -228,6 +228,18 @@
 		assert (const_array.length == 3);
 	}
 
+	static int[] create_array () {
+		return new int[4];
+	}
+
+	static void accept_array (int[] array) {
+		assert (array.length == 4);
+	}
+
+	static void test_array_argument () {
+		accept_array (create_array ());
+	}
+
 	static void main (string[] args) {
 		test_integer_array ();
 		test_string_array ();
@@ -249,6 +261,8 @@
 		test_array_length_of_array_constants ();
 
 		test_array_var_creation_with_structs ();
+
+		test_array_argument ();
 	}
 	
 	public static int inc () {



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