]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Avoid object duplication due to error handling
authorJürg Billeter <j@bitron.ch>
Sun, 30 Nov 2008 15:29:23 +0000 (15:29 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Sun, 30 Nov 2008 15:29:23 +0000 (15:29 +0000)
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

svn path=/trunk/; revision=2102

ChangeLog
gobject/valaccodebasemodule.vala
vala/valalocalvariable.vala
vala/valamethodcall.vala
vala/valasemanticanalyzer.vala

index 215abd41a4a92b3cf6ab7ed1a2bf1884fcd2e1ba..65d60d7fa1c7d5f3b1b9a7bd92a1c49939a00622 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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
+
 2008-11-30  Jürg Billeter  <j@bitron.ch>
 
        * vala/valamethodcall.vala:
index d8295c4e9eb7a21756bf4ec11e9cb5a5ce812424..08836e2a529169427ca7e0b7b860c267bfe94e19 100644 (file)
@@ -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;
index 0b05d91a250acb8d2693bfdb1d8509c85bbf0e13..bea025af37137eeb45f83abc646d8ab2f546d541 100644 (file)
@@ -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;
 
index de7de282a7cd755dc90b36338bca968a8351fa43..c9efd874b75153efae95e0be3476a9c18bbe5ffe 100644 (file)
@@ -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
index fcd82367005fd4c1b98fe949540a2bfea1bafd5a..7909db26a9aca44695fdcbf184bded6e63bd42f6 100644 (file)
@@ -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;