From: Luca Bruno Date: Mon, 30 May 2011 14:11:14 +0000 (+0200) Subject: codegen: Support passing real non-null structs as ref/out varargs X-Git-Tag: 0.13.0~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe78713d001a9058e9768abb8276d81a82ded650;p=thirdparty%2Fvala.git codegen: Support passing real non-null structs as ref/out varargs Fixes bug 651441. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 021629ddd..90d62cbcd 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 2d70b43ea..df46d936a 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 000000000..2387cfe6d --- /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); +}