]> 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 16:21:35 +0000 (18:21 +0200)
codegen/valaccodemethodcallmodule.vala
tests/Makefile.am
tests/methods/bug634753.vala [new file with mode: 0644]

index d2707809d40efcfe768b84c83d07a5fd846f6804..2a2eb249d8f251f7e0deb696e24cebbe2077501c 100644 (file)
@@ -363,7 +363,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 7b886882a4ccc9279d8cd43505b732ab43793b56..d56d2536f498391001a56de1cae8b8bf4e03c7d6 100644 (file)
@@ -85,6 +85,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);
+}