[vala] Fix passing real non null struct arguments to vararg methods
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Fix passing real non null struct arguments to vararg methods
- Date: Fri, 20 Aug 2010 07:26:38 +0000 (UTC)
commit b96ab91fa9e04e9f0eace71b78264b394b028842
Author: Jürg Billeter <j bitron ch>
Date: Fri Aug 6 10:43:03 2010 +0200
Fix passing real non null struct arguments to vararg methods
Based on patch by Luca Bruno, fixes bug 625758.
codegen/valaccodebasemodule.vala | 19 +++++++++++++++----
codegen/valaccodemethodcallmodule.vala | 3 +++
2 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 520e098..0356c54 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4311,11 +4311,14 @@ public class Vala.CCodeBaseModule : CodeGenerator {
if (param.ctype != null) {
cexpr = new CCodeCastExpression (cexpr, param.ctype);
}
+ } else {
+ cexpr = handle_struct_argument (null, arg, cexpr);
}
arg_pos = get_param_pos (param.cparameter_position, ellipsis);
} else {
// default argument position
+ cexpr = handle_struct_argument (null, arg, cexpr);
arg_pos = get_param_pos (i, ellipsis);
}
@@ -4482,11 +4485,19 @@ public class Vala.CCodeBaseModule : CodeGenerator {
}
}
- public CCodeExpression? handle_struct_argument (FormalParameter param, Expression arg, CCodeExpression? cexpr) {
+ public CCodeExpression? handle_struct_argument (FormalParameter? param, Expression arg, CCodeExpression? cexpr) {
+ DataType type;
+ if (param != null) {
+ type = param.variable_type;
+ } else {
+ // varargs
+ type = arg.value_type;
+ }
+
// pass non-simple struct instances always by reference
- if (!(arg.value_type is NullType) && param.variable_type.data_type is Struct && !((Struct) param.variable_type.data_type).is_simple_type ()) {
+ 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.direction == ParameterDirection.IN && !param.variable_type.nullable) {
+ if ((param == null || param.direction == ParameterDirection.IN) && !type.nullable) {
var unary = cexpr as CCodeUnaryExpression;
if (unary != null && unary.operator == CCodeUnaryOperator.POINTER_INDIRECTION) {
// *expr => expr
@@ -4498,7 +4509,7 @@ public class Vala.CCodeBaseModule : CodeGenerator {
// (tmp = expr, &tmp)
var ccomma = new CCodeCommaExpression ();
- var temp_var = get_temp_variable (param.variable_type, true, null, false);
+ var temp_var = get_temp_variable (type, true, null, false);
temp_vars.add (temp_var);
ccomma.append_expression (new CCodeAssignment (get_variable_cexpression (temp_var.name), cexpr));
ccomma.append_expression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_variable_cexpression (temp_var.name)));
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index c3a03e7..ad262fa 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -493,10 +493,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
if (param.ctype != null) {
cexpr = new CCodeCastExpression (cexpr, param.ctype);
}
+ } else {
+ cexpr = handle_struct_argument (null, arg, cexpr);
}
arg_pos = get_param_pos (param.cparameter_position, ellipsis);
} else {
// default argument position
+ cexpr = handle_struct_argument (null, arg, cexpr);
arg_pos = get_param_pos (i, ellipsis);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]