[vala] Capture array size variable in closures as well



commit f155c73cefd4ac7d33352cd2f0d700ff487ac3fa
Author: Adam Folmert <afolmert gmail com>
Date:   Fri Feb 5 02:54:19 2010 +0100

    Capture array size variable in closures as well
    
    Fixes bug 599951.

 codegen/valaccodearraymodule.vala |   10 +++++++++-
 codegen/valaccodebasemodule.vala  |    1 +
 2 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 72d169f..568e462 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -363,7 +363,15 @@ internal class Vala.CCodeArrayModule : CCodeMethodCallModule {
 	public override CCodeExpression get_array_size_cexpression (Expression array_expr) {
 		if (array_expr.symbol_reference is LocalVariable) {
 			var local = (LocalVariable) array_expr.symbol_reference;
-			return get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
+			if (local.captured) {
+				// captured variables are stored on the heap
+				var block = (Block) local.parent_symbol;
+				return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_size_cname (get_variable_cname (local.name)));
+			} else {
+				var size_expr = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
+				return size_expr;
+			}
+
 		} else if (array_expr.symbol_reference is Field) {
 			var field = (Field) array_expr.symbol_reference;
 			var ma = (MemberAccess) array_expr;
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 5c7153b..8981e78 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -1773,6 +1773,7 @@ internal class Vala.CCodeBaseModule : CCodeModule {
 						for (int dim = 1; dim <= array_type.rank; dim++) {
 							data.add_field ("gint", get_array_length_cname (get_variable_cname (local.name), dim));
 						}
+						data.add_field ("gint", get_array_size_cname (get_variable_cname (local.name)));
 					} else if (local.variable_type is DelegateType) {
 						data.add_field ("gpointer", get_delegate_target_cname (get_variable_cname (local.name)));
 						if (local.variable_type.value_owned) {



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