]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix casting of length for "ref" array parameters
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 20 May 2018 15:07:59 +0000 (17:07 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 May 2018 19:15:22 +0000 (21:15 +0200)
codegen/valaccodemethodcallmodule.vala
tests/Makefile.am
tests/methods/bug634753.vala [new file with mode: 0644]

index 923bca54167b303b3d31cac6e4d436a1b14b6aed..2c74f2cecfeecdd594c0d964216f4f40806c0015 100644 (file)
@@ -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);
                                                                }
index 2900039e9339ddeea14ae85563a4c987f43a957e..bb2bbe1da4f049e685eb943fd1f9a07f687286b5 100644 (file)
@@ -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 (file)
index 0000000..fdee042
--- /dev/null
@@ -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);
+}