summaryrefslogtreecommitdiff
path: root/codegen/valaccodemethodcallmodule.vala
diff options
context:
space:
mode:
authorRico Tzschichholz <ricotz@ubuntu.com>2019-07-08 19:11:19 +0200
committerRico Tzschichholz <ricotz@ubuntu.com>2019-07-08 19:55:18 +0200
commite2c653fa317eb9b7757b44a50e384504addfcf62 (patch)
tree00a64628ea379b47ec2c56778e66083f9e25e434 /codegen/valaccodemethodcallmodule.vala
parent39ef848029b261e8cb347d7fe6b8f268234ac41a (diff)
downloadvala-e2c653fa317eb9b7757b44a50e384504addfcf62.tar.gz
codegen: Real structs are allowed by simple generics and passed as reference
Add the required pointer-indirections to fix invalid memory accesses. Fixes https://gitlab.gnome.org/GNOME/vala/issues/819
Diffstat (limited to 'codegen/valaccodemethodcallmodule.vala')
-rw-r--r--codegen/valaccodemethodcallmodule.vala10
1 files changed, 10 insertions, 0 deletions
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 6b292b8c0..4e5cb10b8 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -274,6 +274,10 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
// generic method
int type_param_index = 0;
foreach (var type_arg in ma.get_type_arguments ()) {
+ // real structs are passed by reference for simple generics
+ if (get_ccode_simple_generics (m) && type_arg.is_real_struct_type () && !type_arg.nullable && !(type_arg is PointerType)) {
+ type_arg = new PointerType (type_arg);
+ }
in_arg_map.set (get_param_pos (get_ccode_generic_type_pos (m) + 0.01 * type_param_index), new CCodeIdentifier (get_ccode_name (type_arg)));
type_param_index++;
}
@@ -758,6 +762,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
}
}
+ // real structs are passed by reference for simple generics
+ if (m != null && get_ccode_simple_generics (m) && m.return_type is GenericType
+ && expr.value_type.is_real_struct_type () && !expr.value_type.nullable && !(expr.value_type is PointerType)) {
+ ccall_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeParenthesizedExpression (ccall_expr));
+ }
+
if (m != null && get_ccode_type (m) != null && get_ccode_type (m) != get_ccode_name (m.return_type)) {
// Bug 699956: Implement cast for method return type if [CCode type=] annotation is specified
ccall_expr = new CCodeCastExpression (ccall_expr, get_ccode_name (m.return_type));