[vala/staging: 2/2] gvariant module: Fix serializing multidimensional arrays
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/2] gvariant module: Fix serializing multidimensional arrays
- Date: Sat, 17 Sep 2016 20:24:59 +0000 (UTC)
commit 1014a262c4e248d8a1ab76976936fc43579cbb8d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Sep 13 22:27:17 2015 +0100
gvariant module: Fix serializing multidimensional arrays
The same type signature was being used for every dimension of the array.
https://bugzilla.gnome.org/show_bug.cgi?id=735437
codegen/valagvariantmodule.vala | 8 +++--
tests/Makefile.am | 1 +
tests/dbus/bug735437.test | 68 +++++++++++++++++++++++++++++++++++++++
3 files changed, 74 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valagvariantmodule.vala b/codegen/valagvariantmodule.vala
index 409940e..f476ae3 100644
--- a/codegen/valagvariantmodule.vala
+++ b/codegen/valagvariantmodule.vala
@@ -603,8 +603,10 @@ public class Vala.GVariantModule : GAsyncModule {
ccode.open_for (cforinit, cforcond, cforiter);
CCodeExpression element_variant;
- if (dim < array_type.rank) {
- element_variant = serialize_array_dim (array_type, dim + 1, array_expr,
array_iter_expr);
+ if (array_type.rank > 1) {
+ ArrayType array_type_copy = (ArrayType) array_type.copy ();
+ array_type_copy.rank--;
+ element_variant = serialize_array_dim (array_type_copy, dim + 1, array_expr,
array_iter_expr);
} else {
var element_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION,
array_iter_expr);
element_variant = serialize_expression (array_type.element_type, element_expr);
@@ -615,7 +617,7 @@ public class Vala.GVariantModule : GAsyncModule {
builder_add.add_argument (element_variant);
ccode.add_expression (builder_add);
- if (dim == array_type.rank) {
+ if (array_type.rank == 1) {
var array_iter_incr = new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT,
array_iter_expr);
ccode.add_expression (array_iter_incr);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0832a41..0be664f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -212,6 +212,7 @@ TESTS = \
dbus/dicts.test \
dbus/bug596862.vala \
dbus/bug602003.test \
+ dbus/bug735437.test \
gir/bug651773.test \
gir/bug667751.test \
gir/bug742012.test \
diff --git a/tests/dbus/bug735437.test b/tests/dbus/bug735437.test
new file mode 100644
index 0000000..b3a25cc
--- /dev/null
+++ b/tests/dbus/bug735437.test
@@ -0,0 +1,68 @@
+Packages: gio-2.0
+D-Bus
+
+Program: client
+
+[DBus (name = "org.example.Test")]
+interface Test : Object {
+ public abstract double[] array () throws IOError;
+ public abstract double[,] multi_array () throws IOError;
+ public abstract string[,] multi_array2 () throws IOError;
+}
+
+void main () {
+ // client
+ Test test = Bus.get_proxy_sync (BusType.SESSION, "org.example.Test", "/org/example/test");
+
+ var a = test.array ();
+ assert (a.length == 2 && a[0] == 2.0 && a[1] == 3.0);
+
+ var b = test.multi_array ();
+ assert (b.length[0] == 2 && b.length[1] == 2 && b[0,0] == 2.0 && b[0,1] == 3.0 && b[1,0] == 4.0 &&
b[1,1] == 5.0);
+
+ var c = test.multi_array2 ();
+ assert (c.length[0] == 2 && c.length[1] == 2 && c[0,0] == "foo" && c[0,1] == "bar" && c[1,0] == "baz"
&& c[1,1] == "man");
+}
+
+Program: server
+
+[DBus (name = "org.example.Test")]
+class Test : Object {
+ public double[] array () {
+ return new double[] { 2.0, 3.0 };
+ }
+
+ public double[,] multi_array () {
+ return new double[,] { { 2.0, 3.0 }, { 4.0, 5.0 } };
+ }
+
+ public string[,] multi_array2 () {
+ return new string[,] { { "foo", "bar" }, { "baz", "man" } };
+ }
+}
+
+MainLoop main_loop;
+
+void client_exit (Pid pid, int status) {
+ // client finished, terminate server
+ assert (status == 0);
+ main_loop.quit ();
+}
+
+void main () {
+ var conn = Bus.get_sync (BusType.SESSION);
+ conn.register_object ("/org/example/test", new Test ());
+
+ // try to register service in session bus
+ var request_result = conn.call_sync ("org.freedesktop.DBus", "/org/freedesktop/DBus",
"org.freedesktop.DBus", "RequestName",
+ new Variant ("(su)", "org.example.Test", 0x4), null, 0, -1);
+ assert ((uint) request_result.get_child_value (0) == 1);
+
+ // server ready, spawn client
+ Pid client_pid;
+ Process.spawn_async (null, { "test", "/dbus/bug735437/client" }, null, SpawnFlags.DO_NOT_REAP_CHILD,
null, out client_pid);
+ ChildWatch.add (client_pid, client_exit);
+
+ main_loop = new MainLoop ();
+ main_loop.run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]