[vala/0.48] codegen: Correctly set array-length for NoAccessorMethods properties
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.48] codegen: Correctly set array-length for NoAccessorMethods properties
- Date: Wed, 10 Aug 2022 17:22:07 +0000 (UTC)
commit 675e3017f05b0e9bf7e253360d481940526e7234
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue May 10 18:00:45 2022 +0200
codegen: Correctly set array-length for NoAccessorMethods properties
If value is a null-terminated array then calculate and set its length.
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1316
codegen/valaccodememberaccessmodule.vala | 12 ++++++++++++
tests/Makefile.am | 1 +
tests/objects/property-strv-noaccessor.vala | 15 +++++++++++++++
3 files changed, 28 insertions(+)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index ece18564c..16ab32d0c 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -379,7 +379,19 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF,
ctemp));
ccall.add_argument (new CCodeConstant ("NULL"));
ccode.add_expression (ccall);
+
set_cvalue (expr, ctemp);
+
+ if (get_ccode_array_null_terminated (prop)) {
+ requires_array_length = true;
+ var len_call = new CCodeFunctionCall (new CCodeIdentifier
("_vala_array_length"));
+ len_call.add_argument (ctemp);
+
+ var glib_value = (GLibValue) expr.target_value;
+ glib_value.array_length_cvalues = null;
+ glib_value.append_array_length_cvalue (len_call);
+ glib_value.lvalue = false;
+ }
}
if (prop.get_accessor.value_type is GenericType) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 97c3883ea..0e4500b57 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -530,6 +530,7 @@ TESTS = \
objects/property-simple-type-struct-nullable.vala \
objects/property-static.vala \
objects/property-struct-no-gtype.vala \
+ objects/property-strv-noaccessor.vala \
objects/property-write-only-member-read.test \
objects/regex.vala \
objects/sealed-abstract-class.test \
diff --git a/tests/objects/property-strv-noaccessor.vala b/tests/objects/property-strv-noaccessor.vala
new file mode 100644
index 000000000..6fa394abd
--- /dev/null
+++ b/tests/objects/property-strv-noaccessor.vala
@@ -0,0 +1,15 @@
+class Foo : Object {
+ [CCode (array_length = false, array_null_terminated = true)]
+ [NoAccessorMethod]
+ public string[] bar { owned get; set; }
+}
+
+void main () {
+ string[] bar = { "foo", "bar", "manam" };
+ var foo = new Foo ();
+ foo.bar = bar;
+
+ var manam = foo.bar;
+ assert (manam.length == 3);
+ assert (manam[2] == "manam");
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]