From: Rico Tzschichholz Date: Sun, 20 May 2018 15:07:59 +0000 (+0200) Subject: codegen: Fix casting of length for "ref" array parameters X-Git-Tag: 0.34.18~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60082d942cc99dbf983d243a386055b1928891b6;p=thirdparty%2Fvala.git codegen: Fix casting of length for "ref" array parameters --- diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index 923bca541..2c74f2cec 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 2900039e9..bb2bbe1da 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 000000000..fdee0425c --- /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); +}