[vala/0.34] codegen: Fix casting of length for "ref" array parameters



commit 60082d942cc99dbf983d243a386055b1928891b6
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun May 20 17:07:59 2018 +0200

    codegen: Fix casting of length for "ref" array parameters

 codegen/valaccodemethodcallmodule.vala |    6 +++++-
 tests/Makefile.am                      |    1 +
 tests/methods/bug634753.vala           |    8 ++++++++
 3 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 923bca5..2c74f2c 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -355,7 +355,11 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
                                                                CCodeExpression? array_length_expr = null;
                                                                if (get_ccode_array_length_type (param) != 
null) {
-                                                                       array_length_expr = new 
CCodeCastExpression (get_array_length_cexpression (arg, dim), get_ccode_array_length_type (param));
+                                                                       string length_ctype = 
get_ccode_array_length_type (param);
+                                                                       if (unary.operator == 
UnaryOperator.REF) {
+                                                                               length_ctype = "%s*".printf 
(length_ctype);
+                                                                       }
+                                                                       array_length_expr = new 
CCodeCastExpression (get_array_length_cexpression (arg, dim), length_ctype);
                                                                } else {
                                                                        array_length_expr = 
get_array_length_cexpression (arg, dim);
                                                                }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2900039..bb2bbe1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,7 @@ TESTS = \
        methods/bug620673.vala \
        methods/bug622570.vala \
        methods/bug626783.vala \
+       methods/bug634753.vala \
        methods/bug639054.vala \
        methods/bug642885.vala \
        methods/bug642899.vala \
diff --git a/tests/methods/bug634753.vala b/tests/methods/bug634753.vala
new file mode 100644
index 0000000..fdee042
--- /dev/null
+++ b/tests/methods/bug634753.vala
@@ -0,0 +1,8 @@
+void foo ([CCode (array_length_type = "gsize")] ref uint8[] a) {
+       assert (a.length == 32);
+}
+
+void main () {
+       uint8[] a = new uint8[32];
+       foo (ref a);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]