]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Support passing real non-null structs as ref/out varargs
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 30 May 2011 14:11:14 +0000 (16:11 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 30 May 2011 14:15:42 +0000 (16:15 +0200)
Fixes bug 651441.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/structs/bug651441.vala [new file with mode: 0644]

index 021629ddd44a30b36eafe48572e7812c0275ae24..90d62cbcde5ddb5f367d7b138d6f14804b0465f3 100644 (file)
@@ -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 {
index 2d70b43ea229612c4f19e8a7cc7c7920bb8a17e9..df46d936abd582b6bb8f8fce9c0b741b941b9877 100644 (file)
@@ -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 (file)
index 0000000..2387cfe
--- /dev/null
@@ -0,0 +1,11 @@
+struct Foo {
+       int i;
+}
+
+void test (int n, ...) {
+}
+
+void main () {
+       Foo foo;
+       test (0, out foo);
+}