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

index fb78e5985cef479cab62067102ed1a66f385062a..b2df6643a430cb444e072ef49cfe379b5af72a50 100644 (file)
@@ -365,7 +365,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 943e8fea886d27a0851cd64457c1c9e236228f14..aec6e33f2c2320957f9c397a29455a0ded68cb98 100644 (file)
@@ -86,6 +86,7 @@ TESTS = \
        methods/bug620673.vala \
        methods/bug622570.vala \
        methods/bug626783.vala \
+       methods/bug634753.vala \
        methods/bug639054.vala \
        methods/bug642350.vala \
        methods/bug642885.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);
+}