[vala/staging: 2/2] codegen: Append missing initializer for "_*_size_" of array field in struct
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/2] codegen: Append missing initializer for "_*_size_" of array field in struct
- Date: Tue, 25 Feb 2020 14:07:45 +0000 (UTC)
commit 9682df48333cd4c9327c66414b4328f6c634e366
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Feb 25 12:35:15 2020 +0100
codegen: Append missing initializer for "_*_size_" of array field in struct
Fixes https://gitlab.gnome.org/GNOME/vala/issues/914
codegen/valaccodebasemodule.vala | 3 +++
tests/Makefile.am | 1 +
tests/arrays/struct-field-initializer.vala | 30 ++++++++++++++++++++++++++++++
3 files changed, 34 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 4336fb37f..6cfe04d66 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2724,6 +2724,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
for (int dim = 1; dim <= array_type.rank; dim++) {
clist.append (get_array_length_cvalue
(expr.target_value, dim));
}
+ if (array_type.rank == 1) {
+ clist.append (get_array_length_cvalue
(expr.target_value, 1));
+ }
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 9d54c2ea0..98ed98088 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -87,6 +87,7 @@ TESTS = \
arrays/length-inline-assignment.vala \
arrays/length-type-include.vala \
arrays/struct-field-length-cname.vala \
+ arrays/struct-field-initializer.vala \
arrays/incompatible-integer-elements.test \
arrays/slice-invalid-start.test \
arrays/slice-invalid-stop.test \
diff --git a/tests/arrays/struct-field-initializer.vala b/tests/arrays/struct-field-initializer.vala
new file mode 100644
index 000000000..a51012c04
--- /dev/null
+++ b/tests/arrays/struct-field-initializer.vala
@@ -0,0 +1,30 @@
+[CCode (has_type_id = false)]
+struct Foo {
+ [CCode (array_length = false, array_null_terminated = true)]
+ public unowned string[] array;
+ public int i;
+}
+
+[CCode (has_type_id = false)]
+struct Bar {
+ public unowned string[] array;
+ public int i;
+}
+
+const string[] SARRAY = { "foo", "bar" };
+const Foo FOO = { SARRAY, 23 };
+const Bar BAR = { SARRAY, 42 };
+
+void main () {
+ assert (FOO.array.length == 2);
+ assert (FOO.i == 23);
+ assert (BAR.array.length == 2);
+ assert (BAR.i == 42);
+
+ const Foo foo = { SARRAY, 23 };
+ const Bar bar = { SARRAY, 42 };
+ assert (foo.array.length == 2);
+ assert (foo.i == 23);
+ assert (bar.array.length == 2);
+ assert (bar.i == 42);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]