[vala/staging] codegen: Cast generic return value from g_sequence_get()
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Cast generic return value from g_sequence_get()
- Date: Tue, 25 Jan 2022 16:47:35 +0000 (UTC)
commit 1e4205b25433f181e83342ae6b7592531236680f
Author: Princeton Ferro <princetonferro gmail com>
Date: Tue Jan 25 11:06:23 2022 -0500
codegen: Cast generic return value from g_sequence_get()
Use convert_from_generic_pointer() to generate C code without warnings
when accessing scalar elements from a GSequence.
Addtionally check type arguments of given GSequence during codegen.
In addition to 44195a02c9d26453dc698282deb4947425a4b0b1
codegen/valaccodecontrolflowmodule.vala | 11 ++++++++++-
tests/control-flow/foreach.c-expected | 4 ++--
2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodecontrolflowmodule.vala b/codegen/valaccodecontrolflowmodule.vala
index ce57da62f..9ecbced2f 100644
--- a/codegen/valaccodecontrolflowmodule.vala
+++ b/codegen/valaccodecontrolflowmodule.vala
@@ -423,9 +423,18 @@ public abstract class Vala.CCodeControlFlowModule : CCodeMethodModule {
var get_item = new CCodeFunctionCall (new CCodeIdentifier ("g_sequence_get"));
get_item.add_argument (get_variable_cexpression (sequence_iter));
+ CCodeExpression element_expr = get_item;
+
+ if (collection_type.get_type_arguments ().size != 1) {
+ Report.error (stmt.source_reference, "internal error: missing generic type
argument");
+ stmt.error = true;
+ return;
+ }
+
var element_type = collection_type.get_type_arguments ().get (0).copy ();
element_type.value_owned = false;
- var element_expr = get_cvalue_ (transform_value (new GLibValue (element_type,
get_item, true), stmt.type_reference, stmt));
+ element_expr = convert_from_generic_pointer (element_expr, element_type);
+ element_expr = get_cvalue_ (transform_value (new GLibValue (element_type,
element_expr), stmt.type_reference, stmt));
visit_local_variable (stmt.element_variable);
ccode.add_assignment (get_variable_cexpression (get_local_cname
(stmt.element_variable)), element_expr);
diff --git a/tests/control-flow/foreach.c-expected b/tests/control-flow/foreach.c-expected
index 23225a443..0f9bd45f9 100644
--- a/tests/control-flow/foreach.c-expected
+++ b/tests/control-flow/foreach.c-expected
@@ -281,7 +281,7 @@ test_gsequence_owned (GSequence* sequence)
for (item_iter = g_sequence_get_begin_iter (item_collection); !g_sequence_iter_is_end
(item_iter); item_iter = g_sequence_iter_next (item_iter)) {
GValue* _tmp0_;
GValue* item = NULL;
- _tmp0_ = __g_value_dup0 (g_sequence_get (item_iter));
+ _tmp0_ = __g_value_dup0 ((GValue*) g_sequence_get (item_iter));
item = _tmp0_;
{
guint _tmp1_;
@@ -306,7 +306,7 @@ test_gsequence_unowned (GSequence* sequence)
item_collection = sequence;
for (item_iter = g_sequence_get_begin_iter (item_collection); !g_sequence_iter_is_end
(item_iter); item_iter = g_sequence_iter_next (item_iter)) {
GValue* item = NULL;
- item = g_sequence_get (item_iter);
+ item = (GValue*) g_sequence_get (item_iter);
{
guint _tmp0_;
_tmp0_ = i;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]