[vala] girwriter: Fix index of length parameter for methods returning arrays



commit 9cab3d5f699f15687aef0ca26596b279e57e0814
Author: JÃrg Billeter <j bitron ch>
Date:   Wed Aug 8 20:32:36 2012 +0200

    girwriter: Fix index of length parameter for methods returning arrays
    
    Fixes bug 681411.

 codegen/valagirwriter.vala |   37 ++++++++++++++++++++++++++++++++++---
 1 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valagirwriter.vala b/codegen/valagirwriter.vala
index 3e5c316..597cdac 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<Parameter> 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 ("<parameter name=\"user_data\" transfer-ownership=\"none\" closure=\"%d\">\n", index);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]