vala r2102 - in trunk: . gobject vala



Author: juergbi
Date: Sun Nov 30 15:29:23 2008
New Revision: 2102
URL: http://svn.gnome.org/viewvc/vala?rev=2102&view=rev

Log:
2008-11-30  JÃrg Billeter  <j bitron ch>

	* vala/valalocalvariable.vala:
	* vala/valamethodcall.vala:
	* vala/valasemanticanalyzer.vala:
	* gobject/valaccodebasemodule.vala:

	Avoid object duplication due to error handling


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/vala/valalocalvariable.vala
   trunk/vala/valamethodcall.vala
   trunk/vala/valasemanticanalyzer.vala

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Sun Nov 30 15:29:23 2008
@@ -1239,7 +1239,7 @@
 		}
 
 		foreach (LocalVariable local in local_vars) {
-			if (requires_destroy (local.variable_type)) {
+			if (!local.floating && requires_destroy (local.variable_type)) {
 				var ma = new MemberAccess.simple (local.name);
 				ma.symbol_reference = local;
 				cblock.add_statement (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma)));
@@ -1893,7 +1893,7 @@
 
 		var local_vars = b.get_local_variables ();
 		foreach (LocalVariable local in local_vars) {
-			if (local.active && requires_destroy (local.variable_type)) {
+			if (local.active && !local.floating && requires_destroy (local.variable_type)) {
 				var ma = new MemberAccess.simple (local.name);
 				ma.symbol_reference = local;
 				cfrag.append (new CCodeExpressionStatement (get_unref_expression (new CCodeIdentifier (get_variable_cname (local.name)), local.variable_type, ma)));
@@ -1941,7 +1941,7 @@
 
 		var local_vars = b.get_local_variables ();
 		foreach (LocalVariable local in local_vars) {
-			if (local.active && requires_destroy (local.variable_type)) {
+			if (local.active && !local.floating && requires_destroy (local.variable_type)) {
 				found = true;
 				var ma = new MemberAccess.simple (local.name);
 				ma.symbol_reference = local;

Modified: trunk/vala/valalocalvariable.vala
==============================================================================
--- trunk/vala/valalocalvariable.vala	(original)
+++ trunk/vala/valalocalvariable.vala	Sun Nov 30 15:29:23 2008
@@ -54,6 +54,11 @@
 		}
 	}
 
+	/**
+	 * Floating variables may only be accessed exactly once.
+	 */
+	public bool floating { get; set; }
+
 	private Expression? _initializer;
 	private DataType? _variable_type;
 

Modified: trunk/vala/valamethodcall.vala
==============================================================================
--- trunk/vala/valamethodcall.vala	(original)
+++ trunk/vala/valamethodcall.vala	Sun Nov 30 15:29:23 2008
@@ -419,11 +419,13 @@
 				var old_parent_node = parent_node;
 
 				var local = new LocalVariable (value_type, get_temp_name (), null, source_reference);
+				// use floating variable to avoid unnecessary (and sometimes impossible) copies
+				local.floating = true;
 				var decl = new DeclarationStatement (local, source_reference);
 
 				insert_statement (analyzer.insert_block, decl);
 
-				var temp_access = new MemberAccess.simple (local.name, source_reference);
+				Expression temp_access = new MemberAccess.simple (local.name, source_reference);
 				temp_access.target_type = target_type;
 
 				// don't set initializer earlier as this changes parent_node and parent_statement

Modified: trunk/vala/valasemanticanalyzer.vala
==============================================================================
--- trunk/vala/valasemanticanalyzer.vala	(original)
+++ trunk/vala/valasemanticanalyzer.vala	Sun Nov 30 15:29:23 2008
@@ -174,7 +174,7 @@
 		} else if (sym is LocalVariable) {
 			var local = (LocalVariable) sym;
 			var type = local.variable_type.copy ();
-			if (!lvalue) {
+			if (!lvalue && !local.floating) {
 				type.value_owned = false;
 			}
 			return type;



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