From: Rico Tzschichholz Date: Tue, 25 Feb 2020 11:35:15 +0000 (+0100) Subject: codegen: Append initializer for "_*_size_" of array field in internal struct X-Git-Tag: 0.49.1~217 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=74725956b2c99da3ff289ff2d294c525ff2f85c9;p=thirdparty%2Fvala.git codegen: Append initializer for "_*_size_" of array field in internal struct Fixes https://gitlab.gnome.org/GNOME/vala/issues/914 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 85ea40d5f..536aca2f6 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -2723,6 +2723,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 && field.is_internal_symbol ()) { + clist.append (get_array_length_cvalue (expr.target_value, 1)); + } } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 0eaa2376a..7a6d37d8f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -90,6 +90,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..9534c8490 --- /dev/null +++ b/tests/arrays/struct-field-initializer.vala @@ -0,0 +1,33 @@ +[CCode (has_type_id = false)] +struct Foo { + public unowned string[] array; + public int i; +} + +[CCode (has_type_id = false)] +public 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); + } +}