[vala/wip/transform: 77/81] Fix passing BusName and manage unhandled GErrors



commit 30def299d3d6439fc15ebad802a6500a54fe23f7
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat May 4 15:35:04 2013 +0200

    Fix passing BusName and manage unhandled GErrors

 codegen/valagdbusclienttransformer.vala |    5 ++++
 codegen/valagdbusservertransformer.vala |   16 +++++++++++---
 vala/valacatchclause.vala               |    2 +-
 vala/valacodebuilder.vala               |   33 +++++++++++++++++++++++++++++++
 vala/valacodetransformer.vala           |   18 ++++------------
 vala/valaerrortype.vala                 |    2 +-
 vapi/glib-2.0.vapi                      |    2 +
 7 files changed, 59 insertions(+), 19 deletions(-)
---
diff --git a/codegen/valagdbusclienttransformer.vala b/codegen/valagdbusclienttransformer.vala
index e94b56c..7a30b6a 100644
--- a/codegen/valagdbusclienttransformer.vala
+++ b/codegen/valagdbusclienttransformer.vala
@@ -266,7 +266,12 @@ public class Vala.GDBusClientTransformer : GVariantTransformer {
                        // first try cached value
                        var result = b.add_temp_declaration (null, expression (@"get_cached_property 
(\"$dbus_name\")"));
                        b.open_if (expression (@"$result == null"));
+
+                       b.open_try ();
                        b.add_expression (expression (@"$result = call_sync 
(\"org.freedesktop.DBus.Properties.Get\", new Variant (\"(ss)\", \"$dbus_iface_name\", \"$dbus_name\"), 
GLib.DBusCallFlags.NONE, $timeout, null)"));
+                       b.add_catch_uncaught_error ();
+                       b.close ();
+
                        b.add_expression (expression (@"$result.get (\"(v)\", out $result)"));
                        b.close ();
 
diff --git a/codegen/valagdbusservertransformer.vala b/codegen/valagdbusservertransformer.vala
index bdfd631..ecae793 100644
--- a/codegen/valagdbusservertransformer.vala
+++ b/codegen/valagdbusservertransformer.vala
@@ -47,11 +47,12 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
 
                var iter = b.add_temp_declaration (null, expression ("arguments.iterator ()"));
 
-               var call = (MethodCall) expression (@"object.$(m.name) ()");
-               var finish_call = call;
+               MethodCall call;
+               MethodCall finish_call; 
                Method ready = null;
                CodeBuilder ready_builder = null;
                if (m.coroutine) {
+                       call = (MethodCall) expression (@"object.$(m.name).begin ()");
                        wrapper_method (new VoidType (), "gdbus_server_async_ready " + m.get_full_name (), 
out ready);
                        ready.add_parameter (new Parameter ("source_object", data_type ("GLib.Object", 
false)));
                        ready.add_parameter (new Parameter ("res", data_type ("GLib.AsyncResult", false)));
@@ -59,6 +60,8 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                        ready_builder = new CodeBuilder.for_subroutine (ready);
 
                        finish_call = (MethodCall) expression (@"(($object_type) source_object).$(m.name).end 
(res)");
+               } else {
+                       call = finish_call = (MethodCall) expression (@"object.$(m.name) ()");
                }
 
                var out_args = new string[0];
@@ -70,11 +73,13 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                        if (param.variable_type is ObjectType) {
                                type_name = param.variable_type.data_type.get_full_name ();
                        }
+
                        if (type_name == "GLib.Cancellable") {
                                call.add_argument (expression ("null"));
                                continue;
                        }
                        if (type_name == "GLib.BusName") {
+                               call.add_argument (expression ("(BusName) invocation.get_sender ()"));
                                continue;
                        }
 
@@ -111,8 +116,8 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                } else {
                        b.add_expression (finish_call);
                }
-               b.add_catch (data_type ("GLib.Error"), "e");
-               b.add_expression (expression ("invocation.return_gerror (e)"));
+               b.add_catch_all ("_invocation_gerror_");
+               b.add_expression (expression ("invocation.return_gerror (_invocation_gerror_)"));
                b.add_return ();
                b.close ();
 
@@ -129,7 +134,10 @@ public class Vala.GDBusServerTransformer : GDBusClientTransformer {
                if (fd_list != null) {
                        b.add_expression (expression (@"$reply.set_unix_fd_list ($fd_list)"));
                }
+               b.open_try ();
                b.add_expression (expression (@"invocation.get_connection ().send_message ($reply, 
GLib.DBusSendMessageFlags.NONE, null)"));
+               b.add_catch_uncaught_error ();
+               b.close ();
 
                if (m.coroutine) {
                        pop_builder ();
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index be3d543..7a6391f 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -123,7 +123,7 @@ public class Vala.CatchClause : CodeNode {
                        }
 
                        if (variable_name != null) {
-                               error_variable = new LocalVariable (error_type.copy (), variable_name);
+                               error_variable = new LocalVariable (error_type.copy (), variable_name, null, 
source_reference);
 
                                body.add_local_variable (error_variable);
 
diff --git a/vala/valacodebuilder.vala b/vala/valacodebuilder.vala
index 05801e6..ff43017 100644
--- a/vala/valacodebuilder.vala
+++ b/vala/valacodebuilder.vala
@@ -203,6 +203,16 @@ public class Vala.CodeBuilder {
                stmt.add_catch_clause (new CatchClause (error_type, variable_name, current_block, 
source_reference));
        }
 
+       public void add_catch_all (string? variable_name) {
+               add_catch (data_type ("GLib.Error"), variable_name);
+       }
+
+       public void add_catch_uncaught_error () {
+               add_catch_all ("_uncaught_error_");
+               add_expression (expression ("GLib.critical (_uncaught_error_.message)"));
+               add_expression (expression ("GLib.critical (\"file %s: line %d: uncaught error: %s (%s, 
%d)\", GLib.Log.FILE, GLib.Log.LINE, _uncaught_error_.message, _uncaught_error_.domain.to_string(), 
_uncaught_error_.code)"));
+       }
+
        public void add_statement (Statement statement) {
                current_block.add_statement (statement);
        }
@@ -247,4 +257,27 @@ public class Vala.CodeBuilder {
                        current_block = top as Block;
                } while (current_block == null);
        }
+
+       /* Utilities for building the code */
+
+       public Expression expression (string str) {
+               return new Parser().parse_expression_string (str, source_reference);
+       }
+
+       // only qualified types, will slightly simplify the work of SymbolResolver
+       public static Symbol symbol_from_string (string symbol_string) {
+               Symbol sym = CodeContext.get().root;
+               foreach (unowned string s in symbol_string.split (".")) {
+                       sym = sym.scope.lookup (s);
+               }
+               return sym;
+       }
+
+       // only qualified types, will slightly simplify the work of SymbolResolver
+       public static DataType data_type (string s, bool value_owned = true, bool nullable = false) {
+               DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
+               type.value_owned = value_owned;
+               type.nullable = nullable;
+               return type;
+       }
 }
diff --git a/vala/valacodetransformer.vala b/vala/valacodetransformer.vala
index 8773d51..94bba1f 100644
--- a/vala/valacodetransformer.vala
+++ b/vala/valacodetransformer.vala
@@ -96,24 +96,16 @@ public class Vala.CodeTransformer : CodeVisitor {
                return false;
        }
 
-       public Symbol symbol_from_string (string symbol_string) {
-               Symbol sym = context.root;
-               foreach (unowned string s in symbol_string.split (".")) {
-                       sym = sym.scope.lookup (s);
-               }
-               return sym;
+       public Symbol symbol_from_string (string s) {
+               return CodeBuilder.symbol_from_string (s);
        }
 
-       // only qualified types, will slightly simplify the work of SymbolResolver
-       public DataType data_type (string s, bool value_owned = true, bool nullable = false) {
-               DataType type = SemanticAnalyzer.get_data_type_for_symbol ((TypeSymbol) symbol_from_string 
(s));
-               type.value_owned = value_owned;
-               type.nullable = nullable;
-               return type;
+       public DataType data_type (string s, bool value_owned = true, bool nullable = false) {          
+               return CodeBuilder.data_type (s, value_owned, nullable);
        }
 
        public Expression expression (string str) {
-               return new Parser ().parse_expression_string (str, b.source_reference);
+               return b.expression (str);
        }
 
        public void check (CodeNode node) {
diff --git a/vala/valaerrortype.vala b/vala/valaerrortype.vala
index c7c9f93..d7826e4 100644
--- a/vala/valaerrortype.vala
+++ b/vala/valaerrortype.vala
@@ -112,7 +112,7 @@ public class Vala.ErrorType : ReferenceType {
        }
 
        public override Symbol? get_member (string member_name) {
-               var root_symbol = source_reference.file.context.root;
+               var root_symbol = CodeContext.get().root;
                var gerror_symbol = root_symbol.scope.lookup ("GLib").scope.lookup ("Error");
                return gerror_symbol.scope.lookup (member_name);
        }
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 2e0096a..b28a217 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -2141,6 +2141,8 @@ namespace GLib {
 
        [Assert]
        public static void assert (bool expr);
+       [Assert]
+       public static void assert_no_error (Error e);
        [NoReturn]
        public static void assert_not_reached ();
 


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