[vala/staging] codegen: Use ssize_t for length variables in common array helper functions



commit 636d63af21bba64df8b5e67c8290126c8fcd95cf
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Apr 15 16:49:14 2021 +0200

    codegen: Use ssize_t for length variables in common array helper functions
    
    A signed integer is required, while -1 is allowed as length for arrays

 codegen/valaccodearraymodule.vala | 28 ++++++++++++++--------------
 codegen/valaccodebasemodule.vala  |  6 ++++--
 2 files changed, 18 insertions(+), 16 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index d59538e4d..32a13c897 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -239,14 +239,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var fun = new CCodeFunction (cname, "void");
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", "%s *".printf (get_ccode_name (st))));
-               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (int_type)));
+               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (ssize_t_type)));
 
                push_function (fun);
 
                var ccondarr = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier 
("array"), new CCodeConstant ("NULL"));
                ccode.open_if (ccondarr);
 
-               ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("i"));
+               ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator ("i"));
                append_struct_array_free_loop (st);
 
                ccode.close ();
@@ -279,14 +279,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var fun = new CCodeFunction (cname, "void");
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", "%s *".printf (get_ccode_name (st))));
-               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (int_type)));
+               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (ssize_t_type)));
 
                push_function (fun);
 
                var ccondarr = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier 
("array"), new CCodeConstant ("NULL"));
                ccode.open_if (ccondarr);
 
-               ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("i"));
+               ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator ("i"));
                append_struct_array_free_loop (st);
 
                ccode.close ();
@@ -325,7 +325,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var fun = new CCodeFunction ("_vala_array_destroy", "void");
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", get_ccode_name (pointer_type)));
-               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (int_type)));
+               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (ssize_t_type)));
                fun.add_parameter (new CCodeParameter ("destroy_func", get_ccode_name 
(delegate_target_destroy_type)));
 
                push_function (fun);
@@ -334,7 +334,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                var ccondfunc = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new 
CCodeIdentifier ("destroy_func"), new CCodeConstant ("NULL"));
                ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.AND, ccondarr, ccondfunc));
 
-               ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("i"));
+               ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator ("i"));
                append_vala_array_free_loop ();
 
                ccode.close ();
@@ -349,7 +349,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                fun = new CCodeFunction ("_vala_array_free", "void");
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", get_ccode_name (pointer_type)));
-               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (int_type)));
+               fun.add_parameter (new CCodeParameter ("array_length", get_ccode_name (ssize_t_type)));
                fun.add_parameter (new CCodeParameter ("destroy_func", get_ccode_name 
(delegate_target_destroy_type)));
 
                push_function (fun);
@@ -386,9 +386,9 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", get_ccode_name (pointer_type)));
                fun.add_parameter (new CCodeParameter ("element_size", get_ccode_name (size_t_type)));
-               fun.add_parameter (new CCodeParameter ("src", get_ccode_name (int_type)));
-               fun.add_parameter (new CCodeParameter ("dest", get_ccode_name (int_type)));
-               fun.add_parameter (new CCodeParameter ("length", get_ccode_name (int_type)));
+               fun.add_parameter (new CCodeParameter ("src", get_ccode_name (ssize_t_type)));
+               fun.add_parameter (new CCodeParameter ("dest", get_ccode_name (ssize_t_type)));
+               fun.add_parameter (new CCodeParameter ("length", get_ccode_name (ssize_t_type)));
 
                push_function (fun);
 
@@ -442,13 +442,13 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
        }
 
        public override void append_vala_array_length () {
-               var fun = new CCodeFunction ("_vala_array_length", get_ccode_name (int_type));
+               var fun = new CCodeFunction ("_vala_array_length", get_ccode_name (ssize_t_type));
                fun.modifiers = CCodeModifiers.STATIC;
                fun.add_parameter (new CCodeParameter ("array", get_ccode_name (pointer_type)));
 
                push_function (fun);
 
-               ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("length", new 
CCodeConstant ("0")));
+               ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator ("length", 
new CCodeConstant ("0")));
 
                // return 0 if the array is NULL
                // avoids an extra NULL check on the caller side
@@ -547,7 +547,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
                function.add_parameter (new CCodeParameter ("self", get_ccode_name (array_type)));
                // total length over all dimensions
-               function.add_parameter (new CCodeParameter ("length", get_ccode_name (int_type)));
+               function.add_parameter (new CCodeParameter ("length", get_ccode_name (ssize_t_type)));
                if (array_type.element_type is GenericType) {
                        // dup function array elements
                        string func_name = "%s_dup_func".printf (((GenericType) 
array_type.element_type).type_parameter.name.ascii_down ());
@@ -594,7 +594,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
                        ccode.add_declaration (get_ccode_name (array_type), cvardecl);
                        ccode.add_assignment (new CCodeIdentifier ("result"), gnew);
 
-                       ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("i"));
+                       ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator 
("i"));
 
                        ccode.open_for (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant 
("0")),
                                           new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new 
CCodeIdentifier ("i"), new CCodeIdentifier ("length")),
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index b36fe7b4e..136ba59ce 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -320,6 +320,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        public DataType int64_type;
        public DataType uint64_type;
        public DataType size_t_type;
+       public DataType ssize_t_type;
        public DataType string_type;
        public DataType regex_type;
        public DataType float_type;
@@ -486,6 +487,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                int64_type = new IntegerType ((Struct) root_symbol.scope.lookup ("int64"));
                uint64_type = new IntegerType ((Struct) root_symbol.scope.lookup ("uint64"));
                size_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("size_t"));
+               ssize_t_type = new IntegerType ((Struct) root_symbol.scope.lookup ("ssize_t"));
                float_type = new FloatingType ((Struct) root_symbol.scope.lookup ("float"));
                double_type = new FloatingType ((Struct) root_symbol.scope.lookup ("double"));
                string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
@@ -5840,7 +5842,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                function.modifiers = CCodeModifiers.STATIC;
 
                function.add_parameter (new CCodeParameter ("stack", "%s *".printf (get_ccode_name 
(array_type.element_type))));
-               function.add_parameter (new CCodeParameter ("stack_length", get_ccode_name (int_type)));
+               function.add_parameter (new CCodeParameter ("stack_length", get_ccode_name (ssize_t_type)));
                if (array_type.element_type is StructValueType) {
                        function.add_parameter (new CCodeParameter ("needle", "const %s *".printf 
(get_ccode_name (array_type.element_type))));
                } else {
@@ -5849,7 +5851,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
                push_function (function);
 
-               ccode.add_declaration (get_ccode_name (int_type), new CCodeVariableDeclarator ("i"));
+               ccode.add_declaration (get_ccode_name (ssize_t_type), new CCodeVariableDeclarator ("i"));
 
                var cloop_initializer = new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant 
("0"));
                var cloop_condition = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new 
CCodeIdentifier ("i"), new CCodeIdentifier ("stack_length"));


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