From: Rico Tzschichholz Date: Fri, 26 Jan 2024 14:26:46 +0000 (+0100) Subject: codegen: Cast generic return value from g_ptr_array_index() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fee6dadcd4a8cc772c190a3e6bf9820f8fe2041e;p=thirdparty%2Fvala.git codegen: Cast generic return value from g_ptr_array_index() 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 --- diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala index 9a68579b3..e8f9df610 100644 --- a/codegen/valaccodecontrolflowmodule.vala +++ b/codegen/valaccodecontrolflowmodule.vala @@ -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)); diff --git a/tests/basic-types/gptrarray.c-expected b/tests/basic-types/gptrarray.c-expected index d771e84f1..401c50446 100644 --- a/tests/basic-types/gptrarray.c-expected +++ b/tests/basic-types/gptrarray.c-expected @@ -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_; diff --git a/tests/control-flow/foreach.c-expected b/tests/control-flow/foreach.c-expected index 3263a32ef..ba3697e71 100644 --- a/tests/control-flow/foreach.c-expected +++ b/tests/control-flow/foreach.c-expected @@ -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;