[vala/staging] codegen: Correctly transform arguments of Array.resize() for realloc (POSIX)



commit b3ff8af3abb872ad5a98a0661097b266ede0f2c5
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Oct 19 17:41:31 2019 +0200

    codegen: Correctly transform arguments of Array.resize() for realloc (POSIX)

 codegen/valaccodemethodcallmodule.vala | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 1fa3aebb2..c5b36f86a 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -193,7 +193,7 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                // the complete call expression, might include casts, comma expressions, and/or assignments
                CCodeExpression ccall_expr = ccall;
 
-               if (m is ArrayResizeMethod) {
+               if (m is ArrayResizeMethod && context.profile != Profile.POSIX) {
                        var array_type = (ArrayType) ma.inner.value_type;
                        in_arg_map.set (get_param_pos (0), new CCodeIdentifier (get_ccode_name 
(array_type.element_type)));
                } else if (m is ArrayMoveMethod) {
@@ -494,6 +494,13 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        arg_pos = get_param_pos (param != null ? get_ccode_pos (param) : i, ellipsis);
                        carg_map.set (arg_pos, cexpr);
 
+                       if (m is ArrayResizeMethod && context.profile == Profile.POSIX) {
+                               var csizeof = new CCodeIdentifier ("sizeof (%s)".printf (get_ccode_name 
(((ArrayType) ma.inner.value_type).element_type)));
+                               carg_map.set (arg_pos, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, 
csizeof, cexpr));
+                       } else {
+                               carg_map.set (arg_pos, cexpr);
+                       }
+
                        if (arg is NamedArgument && ellipsis) {
                                var named_arg = (NamedArgument) arg;
                                string name = string.joinv ("-", named_arg.name.split ("_"));


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