[vala/staging: 2/3] signalmodule: Add support for array-parameters with rank > 1
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 2/3] signalmodule: Add support for array-parameters with rank > 1
- Date: Sun, 5 Mar 2017 14:47:03 +0000 (UTC)
commit 972d5686467c6518c27fd9bbf98b1d45ac202698
Author: Francisco Serna <Francisco Serna jhuapl edu>
Date: Tue Feb 14 16:05:13 2017 -0500
signalmodule: Add support for array-parameters with rank > 1
https://bugzilla.gnome.org/show_bug.cgi?id=778632
codegen/valaccodeattribute.vala | 6 +++++-
codegen/valagsignalmodule.vala | 22 ++++++++++++++--------
tests/Makefile.am | 1 +
tests/objects/bug778632.vala | 22 ++++++++++++++++++++++
4 files changed, 42 insertions(+), 9 deletions(-)
---
diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala
index 7725aa7..2557900 100644
--- a/codegen/valaccodeattribute.vala
+++ b/codegen/valaccodeattribute.vala
@@ -951,7 +951,11 @@ public class Vala.CCodeAttribute : AttributeCache {
if (((ArrayType) node).element_type.data_type.get_full_name () == "string") {
return "BOXED,INT";
} else {
- return "POINTER,INT";
+ var ret = "POINTER";
+ for (var i = 0; i < ((ArrayType) node).rank; i++) {
+ ret = "%s,INT".printf (ret);
+ }
+ return ret;
}
} else if (node is VoidType) {
return "VOID";
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index f995f27..2a1afd0 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -220,8 +220,10 @@ public class Vala.GSignalModule : GObjectModule {
callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf (n_params),
get_value_type_name_from_parameter (p)));
n_params++;
if (p.variable_type.is_array ()) {
- callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf (n_params),
"gint"));
- n_params++;
+ for (var j = 0; j < ((ArrayType) p.variable_type).rank; j++) {
+ callback_decl.add_parameter (new CCodeParameter ("arg_%d".printf
(n_params), "gint"));
+ n_params++;
+ }
}
}
callback_decl.add_parameter (new CCodeParameter ("data2", "gpointer"));
@@ -289,10 +291,12 @@ public class Vala.GSignalModule : GObjectModule {
fc.add_argument (inner_fc);
i++;
if (is_array) {
- inner_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_int"));
- inner_fc.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS,
new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
- fc.add_argument (inner_fc);
- i++;
+ for (var j = 0; j < ((ArrayType) p.variable_type).rank; j++) {
+ inner_fc = new CCodeFunctionCall (new CCodeIdentifier
("g_value_get_int"));
+ inner_fc.add_argument (new CCodeBinaryExpression
(CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
+ fc.add_argument (inner_fc);
+ i++;
+ }
}
}
fc.add_argument (new CCodeIdentifier ("data2"));
@@ -404,7 +408,7 @@ public class Vala.GSignalModule : GObjectModule {
foreach (Parameter param in params) {
params_len++;
if (param.variable_type.is_array ()) {
- params_len++;
+ params_len += ((ArrayType) param.variable_type).rank;
}
}
@@ -416,7 +420,9 @@ public class Vala.GSignalModule : GObjectModule {
} else {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
}
- csignew.add_argument (new CCodeConstant ("G_TYPE_INT"));
+ for (var i = 0; i < ((ArrayType) param.variable_type).rank; i++) {
+ csignew.add_argument (new CCodeConstant ("G_TYPE_INT"));
+ }
} else if (param.variable_type is PointerType || param.variable_type.type_parameter
!= null || param.direction != ParameterDirection.IN) {
csignew.add_argument (new CCodeConstant ("G_TYPE_POINTER"));
} else if (param.variable_type is ErrorType) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c656d20..2d0b2ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -213,6 +213,7 @@ TESTS = \
objects/bug615830-1.test \
objects/bug615830-2.test \
objects/bug766739.vala \
+ objects/bug778632.vala \
errors/errors.vala \
errors/bug567181.vala \
errors/bug579101.vala \
diff --git a/tests/objects/bug778632.vala b/tests/objects/bug778632.vala
new file mode 100644
index 0000000..cd78801
--- /dev/null
+++ b/tests/objects/bug778632.vala
@@ -0,0 +1,22 @@
+class Foo : Object {
+ public signal void bar (int[,,] a);
+
+ public void bar_emit () {
+ int[2,3,2] a = {{{1, 2}, {3, 4}, {5, 6}}, {{7, 8}, {9, 10}, {11, 12}}};
+ bar (a);
+ }
+}
+
+void bar_callback (int[,,] a) {
+ assert (a.length[0] == 2);
+ assert (a.length[1] == 3);
+ assert (a.length[2] == 2);
+ assert (a[0,2,0] == 5);
+ assert (a[1,2,1] == 12);
+}
+
+void main () {
+ var foo = new Foo ();
+ foo.bar.connect (bar_callback);
+ foo.bar_emit ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]