[vala] codegen: Support passing real non-null structs as ref/out varargs



commit fe78713d001a9058e9768abb8276d81a82ded650
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon May 30 16:11:14 2011 +0200

    codegen: Support passing real non-null structs as ref/out varargs
    
    Fixes bug 651441.

 codegen/valaccodebasemodule.vala |    9 +++++----
 tests/Makefile.am                |    1 +
 tests/structs/bug651441.vala     |   11 +++++++++++
 3 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 021629d..90d62cb 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4305,14 +4305,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			type = arg.value_type;
 		}
 
+		var unary = arg as UnaryExpression;
 		// pass non-simple struct instances always by reference
 		if (!(arg.value_type is NullType) && type.is_real_struct_type ()) {
 			// we already use a reference for arguments of ref, out, and nullable parameters
-			if ((param == null || param.direction == ParameterDirection.IN) && !type.nullable) {
-				var unary = cexpr as CCodeUnaryExpression;
-				if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
+			if (!(unary != null && (unary.operator == UnaryOperator.OUT || unary.operator == UnaryOperator.REF)) && !type.nullable) {
+				var cunary = cexpr as CCodeUnaryExpression;
+				if (cunary != null && cunary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
 					// *expr => expr
-					return unary.inner;
+					return cunary.inner;
 				} else if (cexpr is CCodeIdentifier || cexpr is CCodeMemberAccess) {
 					return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cexpr);
 				} else {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2d70b43..df46d93 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ TESTS = \
 	structs/bug613825.vala \
 	structs/bug621176.vala \
 	structs/bug622422.vala \
+	structs/bug651441.vala \
 	delegates/delegates.vala \
 	delegates/bug595610.vala \
 	delegates/bug595639.vala \
diff --git a/tests/structs/bug651441.vala b/tests/structs/bug651441.vala
new file mode 100644
index 0000000..2387cfe
--- /dev/null
+++ b/tests/structs/bug651441.vala
@@ -0,0 +1,11 @@
+struct Foo {
+	int i;
+}
+
+void test (int n, ...) {
+}
+
+void main () {
+	Foo foo;
+	test (0, out foo);
+}



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