[vala/staging: 2/2] codegen: Don't free temp-var for element-access to array with boxed structs
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/2] codegen: Don't free temp-var for element-access to array with boxed structs
- Date: Sun, 11 Apr 2021 16:09:09 +0000 (UTC)
commit c9c7c782f02843061fa9d13dfba917ad8f295272
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Apr 11 18:05:08 2021 +0200
codegen: Don't free temp-var for element-access to array with boxed structs
Check the symbol_reference of inner element-access as needed.
Regression of 63551acaf0d83fac8b50904c2759c1098fbfaa71
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1174
codegen/valaccodebasemodule.vala | 3 +++
tests/Makefile.am | 1 +
tests/arrays/cast-struct-boxed-element-access.vala | 22 ++++++++++++++++++++++
3 files changed, 26 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index fc25b327f..4ea6794c4 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5477,6 +5477,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
while (inner_expr is CastExpression) {
inner_expr = ((CastExpression) inner_expr).inner;
}
+ if (inner_expr is ElementAccess) {
+ inner_expr = ((ElementAccess) inner_expr).container;
+ }
if (!(inner_expr.symbol_reference is Variable)) {
// heap allocated struct leaked, destroy it
var value = new GLibValue (new PointerType (new VoidType ()), innercexpr);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a802bc8fb..346c67e2d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -100,6 +100,7 @@ TESTS = \
constants/strings.vala \
namespace/unique.vala \
arrays/cast-silent-invalid.test \
+ arrays/cast-struct-boxed-element-access.vala \
arrays/class-field-initializer.vala \
arrays/class-field-length-cname.vala \
arrays/constant-element-access.vala \
diff --git a/tests/arrays/cast-struct-boxed-element-access.vala
b/tests/arrays/cast-struct-boxed-element-access.vala
new file mode 100644
index 000000000..356ecbd50
--- /dev/null
+++ b/tests/arrays/cast-struct-boxed-element-access.vala
@@ -0,0 +1,22 @@
+struct Foo {
+ public int i;
+}
+
+void main () {
+ var foo = new Foo?[] { { 23 }, { 42 }, { 4711 } };
+ {
+ Foo f = foo[0];
+ assert (f.i == 23);
+ assert (foo[0].i == 23);
+ }
+ {
+ Foo f = (Foo) foo[1];
+ assert (f.i == 42);
+ assert (foo[1].i == 42);
+ }
+ {
+ Foo f = (!) foo[2];
+ assert (f.i == 4711);
+ assert (foo[2].i == 4711);
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]