From: Jürg Billeter Date: Wed, 8 Aug 2012 18:32:36 +0000 (+0200) Subject: girwriter: Fix index of length parameter for methods returning arrays X-Git-Tag: 0.17.5~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9cab3d5f699f15687aef0ca26596b279e57e0814;p=thirdparty%2Fvala.git girwriter: Fix index of length parameter for methods returning arrays Fixes bug 681411. --- diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala index 3e5c3164b..597cdacca 100644 --- a/codegen/valagirwriter.vala +++ b/codegen/valagirwriter.vala @@ -1,6 +1,6 @@ /* valagirwriter.vala * - * Copyright (C) 2008-2011 Jürg Billeter + * Copyright (C) 2008-2012 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -823,10 +823,43 @@ public class Vala.GIRWriter : CodeVisitor { } } + void skip_implicit_params (DataType type, ref int index, bool has_array_length) { + if (type is ArrayType && has_array_length) { + index++; + } else if (type is DelegateType) { + index++; + if (type.value_owned) { + index++; + } + } + } + private void write_params_and_return (List params, DataType? return_type, bool return_array_length, string? return_comment = null, bool constructor = false, DataType? instance_type = null, bool user_data = false) { int last_index = 0; bool ret_is_struct = return_type != null && return_type.is_real_non_null_struct_type (); + if (params.size != 0 || instance_type != null || (return_type is ArrayType && return_array_length) || (return_type is DelegateType) || ret_is_struct) { + int index = 0; + + if (instance_type != null) { + index++; + } + + foreach (Parameter param in params) { + index++; + + skip_implicit_params (param.variable_type, ref index, CCodeBaseModule.get_ccode_array_length (param)); + } + + if (ret_is_struct) { + index++; + } else { + skip_implicit_params (return_type, ref index, return_array_length); + } + + last_index = index - 1; + } + if (return_type != null && !ret_is_struct) { write_param_or_return (return_type, false, ref last_index, return_array_length, null, return_comment, ParameterDirection.IN, constructor); } else if (ret_is_struct) { @@ -856,8 +889,6 @@ public class Vala.GIRWriter : CodeVisitor { write_implicit_params (return_type, ref index, return_array_length, "result", ParameterDirection.OUT); } - last_index = index - 1; - if (user_data) { write_indent (); buffer.append_printf ("\n", index);