From: Jürg Billeter Date: Sun, 30 Nov 2008 15:29:23 +0000 (+0000) Subject: Avoid object duplication due to error handling X-Git-Tag: VALA_0_5_2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=372a51324900f602cefdd55682191f184ba2764a;p=thirdparty%2Fvala.git Avoid object duplication due to error handling 2008-11-30 Jürg Billeter * vala/valalocalvariable.vala: * vala/valamethodcall.vala: * vala/valasemanticanalyzer.vala: * gobject/valaccodebasemodule.vala: Avoid object duplication due to error handling svn path=/trunk/; revision=2102 --- diff --git a/ChangeLog b/ChangeLog index 215abd41a..65d60d7fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2008-11-30 Jürg Billeter + + * vala/valalocalvariable.vala: + * vala/valamethodcall.vala: + * vala/valasemanticanalyzer.vala: + * gobject/valaccodebasemodule.vala: + + Avoid object duplication due to error handling + 2008-11-30 Jürg Billeter * vala/valamethodcall.vala: diff --git a/gobject/valaccodebasemodule.vala b/gobject/valaccodebasemodule.vala index d8295c4e9..08836e2a5 100644 --- a/gobject/valaccodebasemodule.vala +++ b/gobject/valaccodebasemodule.vala @@ -1239,7 +1239,7 @@ public class Vala.CCodeBaseModule : CCodeModule { } 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 @@ public class Vala.CCodeBaseModule : CCodeModule { 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 @@ public class Vala.CCodeBaseModule : CCodeModule { 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; diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala index 0b05d91a2..bea025af3 100644 --- a/vala/valalocalvariable.vala +++ b/vala/valalocalvariable.vala @@ -54,6 +54,11 @@ public class Vala.LocalVariable : Symbol { } } + /** + * Floating variables may only be accessed exactly once. + */ + public bool floating { get; set; } + private Expression? _initializer; private DataType? _variable_type; diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index de7de282a..c9efd874b 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -419,11 +419,13 @@ public class Vala.MethodCall : Expression { 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 diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index fcd823670..7909db26a 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -174,7 +174,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor { } 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;