[vala/emit-let] codegen: Fix array ownership transfer



commit 308114f629734665de3f05d8201cbf435847617b
Author: Luca Bruno <lucabru src gnome org>
Date:   Thu Mar 17 18:29:28 2011 +0100

    codegen: Fix array ownership transfer

 codegen/valaccodeassignmentmodule.vala |   26 ++++++++++++++++----------
 codegen/valaccodebasemodule.vala       |   26 +++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 13 deletions(-)
---
diff --git a/codegen/valaccodeassignmentmodule.vala b/codegen/valaccodeassignmentmodule.vala
index 3f6dd65..9543cb9 100644
--- a/codegen/valaccodeassignmentmodule.vala
+++ b/codegen/valaccodeassignmentmodule.vala
@@ -193,17 +193,23 @@ public class Vala.CCodeAssignmentModule : CCodeMemberAccessModule {
 		ccode.add_assignment (get_cvalue_ (lvalue), get_cvalue_ (value));
 
 		if (array_type != null) {
-			if (!variable.no_array_length && !variable.array_null_terminated) {
-				for (int dim = 1; dim <= array_type.rank; dim++) {
-					ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
+			if (!variable.no_array_length) {
+				if (!get_no_array_length (value)) {
+					for (int dim = 1; dim <= array_type.rank; dim++) {
+						ccode.add_assignment (get_array_length_cvalue (lvalue, dim), get_array_length_cvalue (value, dim));
+					}
+				} else if (get_array_null_terminated (value)) {
+					requires_array_length = true;
+					var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
+					len_call.add_argument (get_cvalue_ (value));
+
+					ccode.add_assignment (get_array_length_cvalue (lvalue, 1), len_call);
 				}
-				if (array_type.rank == 1) {
-					if (get_array_size_cvalue (lvalue) != null) {
-						if (get_array_size_cvalue (value) != null) {
-							ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_size_cvalue (value));
-						} else {
-							ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_length_cvalue (value, 1));
-						}
+				if (array_type.rank == 1 && get_array_size_cvalue (lvalue) != null) {
+					if (get_array_size_cvalue (value) != null) {
+						ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_size_cvalue (value));
+					} else {
+						ccode.add_assignment (get_array_size_cvalue (lvalue), get_array_length_cvalue (lvalue, 1));
 					}
 				}
 			}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a25b5fc..4167f01 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4767,7 +4767,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 	}
 
 	public override void visit_reference_transfer_expression (ReferenceTransferExpression expr) {
-		/* (tmp = var, var = null, tmp) */
+		/* tmp = expr.inner; expr.inner = NULL; expr = tmp; */
 		var temp_decl = get_temp_variable (expr.value_type, true, expr, false);
 		emit_temp_var (temp_decl);
 		var cvar = get_variable_cexpression (temp_decl.name);
@@ -4781,8 +4781,28 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 
 		var array_type = expr.value_type as ArrayType;
 		if (array_type != null) {
-			for (int dim = 1; dim <= array_type.rank; dim++) {
-				append_array_length (expr, get_array_length_cexpression (expr.inner, dim));
+			var value = (GLibValue) expr.inner.target_value;
+			if (!value.no_array_length) {
+				for (int dim = 1; dim <= array_type.rank; dim++) {
+					var len_decl = get_temp_variable (int_type, true, expr, false);
+					emit_temp_var (len_decl);
+					ccode.add_assignment (get_variable_cexpression (len_decl.name), get_array_length_cexpression (expr.inner, dim));
+					append_array_length (expr, get_variable_cexpression (len_decl.name));
+				}
+			} else if (value.array_null_terminated) {
+				requires_array_length = true;
+				var len_decl = get_temp_variable (int_type, true, expr, false);
+				emit_temp_var (len_decl);
+
+				var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
+				len_call.add_argument (get_cvalue_ (value));
+
+				ccode.add_assignment (get_variable_cexpression (len_decl.name), len_call);
+				append_array_length (expr, get_variable_cexpression (len_decl.name));
+			} else {
+				for (int dim = 1; dim <= array_type.rank; dim++) {
+					append_array_length (expr, new CCodeConstant ("-1"));
+				}
 			}
 		}
 



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