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.41.90~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=049b9b3943831e6dd242889a8196bd88b7858268;p=thirdparty%2Fvala.git codegen: Fix casting of length for "ref" array parameters --- diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala index fb78e5985..b2df6643a 100644 --- a/codegen/valaccodemethodcallmodule.vala +++ b/codegen/valaccodemethodcallmodule.vala @@ -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); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 943e8fea8..aec6e33f2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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); +}