]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Cast generic return value from g_ptr_array_index()
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 26 Jan 2024 14:26:46 +0000 (15:26 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 26 Jan 2024 14:26:46 +0000 (15:26 +0100)
Use convert_from_generic_pointer() to generate C code without warnings
when accessing scalar elements from a GPtrArray.

Found by -Werror=int-conversion

In addition to f904c7e269c7f7b0a6dcefa4f8f892b981a71917

codegen/valaccodecontrolflowmodule.vala
tests/basic-types/gptrarray.c-expected
tests/control-flow/foreach.c-expected

index 9a68579b3fd703d8b6991215d628a3326cab54a9..e8f9df6106dafe10e9e44b7dca0138b66a976a25 100644 (file)
@@ -361,6 +361,7 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
                        get_item.add_argument (get_variable_cexpression (arr_index));
 
                        CCodeExpression element_expr = get_item;
+                       element_expr = convert_from_generic_pointer (element_expr, stmt.element_variable.variable_type);
 
                        if (stmt.type_reference.value_owned) {
                                element_expr = get_cvalue_ (copy_value (new GLibValue (stmt.type_reference, element_expr), stmt.element_variable));
index d771e84f10e2bd9507e2a4cc4da7d43007c550f9..401c50446eaf9a6bf94a7694bd561229462a9496 100644 (file)
@@ -460,7 +460,7 @@ _vala_main (void)
                        element_collection = _tmp21_;
                        for (element_index = 0; element_index < element_collection->len; element_index = element_index + 1) {
                                Foo* element = NULL;
-                               element = g_ptr_array_index (element_collection, element_index);
+                               element = (Foo*) g_ptr_array_index (element_collection, element_index);
                                {
                                        gint _tmp22_;
                                        Foo* _tmp23_;
@@ -512,7 +512,7 @@ _vala_main (void)
                        for (element_index = 0; element_index < element_collection->len; element_index = element_index + 1) {
                                Foo* _tmp31_;
                                Foo* element = NULL;
-                               _tmp31_ = _g_object_ref0 (g_ptr_array_index (element_collection, element_index));
+                               _tmp31_ = _g_object_ref0 ((Foo*) g_ptr_array_index (element_collection, element_index));
                                element = _tmp31_;
                                {
                                        gint _tmp32_;
@@ -724,7 +724,7 @@ _vala_main (void)
                        element_collection = _tmp102_;
                        for (element_index = 0; element_index < element_collection->len; element_index = element_index + 1) {
                                Foo* element = NULL;
-                               element = g_ptr_array_index (element_collection, element_index);
+                               element = (Foo*) g_ptr_array_index (element_collection, element_index);
                                {
                                        gint _tmp103_;
                                        Foo* _tmp104_;
@@ -776,7 +776,7 @@ _vala_main (void)
                        for (element_index = 0; element_index < element_collection->len; element_index = element_index + 1) {
                                Foo* _tmp112_;
                                Foo* element = NULL;
-                               _tmp112_ = _g_object_ref0 (g_ptr_array_index (element_collection, element_index));
+                               _tmp112_ = _g_object_ref0 ((Foo*) g_ptr_array_index (element_collection, element_index));
                                element = _tmp112_;
                                {
                                        gint _tmp113_;
index 3263a32efb97cd7c3e8ce8b425632ae7ad5e8c26..ba3697e71b1c0a59a7c3fb82680992996e1bf6f8 100644 (file)
@@ -177,7 +177,7 @@ test_generic_array_owned (GPtrArray* array)
                for (item_index = 0; item_index < item_collection->len; item_index = item_index + 1) {
                        GValue* _tmp0_;
                        GValue* item = NULL;
-                       _tmp0_ = __g_value_dup0 (g_ptr_array_index (item_collection, item_index));
+                       _tmp0_ = __g_value_dup0 ((GValue*) g_ptr_array_index (item_collection, item_index));
                        item = _tmp0_;
                        {
                                guint _tmp1_;
@@ -202,7 +202,7 @@ test_generic_array_unowned (GPtrArray* array)
                item_collection = array;
                for (item_index = 0; item_index < item_collection->len; item_index = item_index + 1) {
                        GValue* item = NULL;
-                       item = g_ptr_array_index (item_collection, item_index);
+                       item = (GValue*) g_ptr_array_index (item_collection, item_index);
                        {
                                guint _tmp0_;
                                _tmp0_ = i;