[Vala] [PATCH] Clean up unused GError in case of catch statement without arguments



When catch statement has no arguments, no access to a GError is possible
from Vala source code. Therefore, do not create temporary variable which
is not used. Also, clear error object as it is not passed upwards then.
---
 codegen/valagerrormodule.vala |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 98528d3..ecbcd1c 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -337,9 +337,16 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
                        closure_struct.add_field ("GError *", variable_name);
                        cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment 
(get_variable_cexpression (variable_name), get_variable_cexpression ("_inner_error_"))));
                } else {
-                       var cdecl = new CCodeDeclaration ("GError *");
-                       cdecl.add_declarator (new CCodeVariableDeclarator (variable_name, 
get_variable_cexpression ("_inner_error_")));
-                       cblock.add_statement (cdecl);
+                       if (clause.variable_name != null) {
+                               var cdecl = new CCodeDeclaration ("GError *");
+                               cdecl.add_declarator (new CCodeVariableDeclarator (variable_name, 
get_variable_cexpression ("_inner_error_")));
+                               cblock.add_statement (cdecl);
+                       } else {
+                               var cclear = new CCodeFunctionCall (new CCodeIdentifier ("g_clear_error"));
+                               cclear.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, 
get_variable_cexpression ("_inner_error_")));
+                               cblock.add_statement (new CCodeComment ("Error object is not used within 
catch statement, clear it"));
+                               cblock.add_statement (new CCodeExpressionStatement (cclear));
+                       }
                }
                cblock.add_statement (new CCodeExpressionStatement (new CCodeAssignment 
(get_variable_cexpression ("_inner_error_"), new CCodeConstant ("NULL"))));
 
-- 
1.6.5



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