From: Carlos Garnacho Date: Mon, 6 Mar 2017 13:23:19 +0000 (+0100) Subject: codegen: Check there is a return error location before using it X-Git-Tag: 0.35.7~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=379a7b14f7e5854b9d6fb791e3420030d6e2705b;p=thirdparty%2Fvala.git codegen: Check there is a return error location before using it Fixes client-side dbus generation on methods that don't throw any error. https://bugzilla.gnome.org/show_bug.cgi?id=779652 --- diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala index a0151f6e3..31cd12e55 100644 --- a/codegen/valagdbusclientmodule.vala +++ b/codegen/valagdbusclientmodule.vala @@ -565,6 +565,14 @@ public class Vala.GDBusClientModule : GDBusModule { cfile.add_include ("gio/gunixfdlist.h"); } + bool has_error_argument = (m.get_error_types ().size > 0); + CCodeExpression error_argument; + if (has_error_argument) { + error_argument = new CCodeIdentifier ("error"); + } else { + error_argument = new CCodeConstant ("NULL"); + } + if (call_type != CallType.FINISH) { var destination = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_proxy_get_name")); destination.add_argument (gdbusproxy); @@ -671,7 +679,7 @@ public class Vala.GDBusClientModule : GDBusModule { ccall.add_argument (timeout); ccall.add_argument (new CCodeConstant ("NULL")); ccall.add_argument (cancellable); - ccall.add_argument (new CCodeIdentifier ("error")); + ccall.add_argument (error_argument); ccode.add_assignment (new CCodeIdentifier ("_reply_message"), ccall); } else if (call_type == CallType.NO_REPLY) { var set_flags = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_set_flags")); @@ -684,7 +692,7 @@ public class Vala.GDBusClientModule : GDBusModule { ccall.add_argument (new CCodeIdentifier ("_message")); ccall.add_argument (new CCodeConstant ("G_DBUS_SEND_MESSAGE_FLAGS_NONE")); ccall.add_argument (new CCodeConstant ("NULL")); - ccall.add_argument (new CCodeIdentifier ("error")); + ccall.add_argument (error_argument); ccode.add_expression (ccall); } else if (call_type == CallType.ASYNC) { ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_connection_send_message_with_reply")); @@ -737,7 +745,7 @@ public class Vala.GDBusClientModule : GDBusModule { ccode.add_assignment (new CCodeIdentifier ("_inner_res"), inner_res); ccall.add_argument (new CCodeIdentifier ("_inner_res")); - ccall.add_argument (new CCodeConstant ("error")); + ccall.add_argument (error_argument); ccode.add_assignment (new CCodeIdentifier ("_reply_message"), ccall); // _inner_res is guaranteed to be non-NULL, so just unref it @@ -749,7 +757,7 @@ public class Vala.GDBusClientModule : GDBusModule { inner_res.add_argument (new CCodeCastExpression (new CCodeIdentifier ("_res_"), "GSimpleAsyncResult *")); ccall.add_argument (inner_res); - ccall.add_argument (new CCodeConstant ("error")); + ccall.add_argument (error_argument); ccode.add_assignment (new CCodeIdentifier ("_reply_message"), ccall); } } @@ -769,7 +777,7 @@ public class Vala.GDBusClientModule : GDBusModule { // return on remote error var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_dbus_message_to_gerror")); ccall.add_argument (new CCodeIdentifier ("_reply_message")); - ccall.add_argument (new CCodeIdentifier ("error")); + ccall.add_argument (error_argument); ccode.open_if (ccall); ccode.add_expression (unref_reply); return_default_value (m.return_type); @@ -816,7 +824,8 @@ public class Vala.GDBusClientModule : GDBusModule { var target = new CCodeIdentifier ("_vala_%s".printf (param.name)); bool may_fail; - receive_dbus_value (param.variable_type, new CCodeIdentifier ("_reply_message"), new CCodeIdentifier ("_reply_iter"), target, param, new CCodeIdentifier ("error"), out may_fail); + + receive_dbus_value (param.variable_type, new CCodeIdentifier ("_reply_message"), new CCodeIdentifier ("_reply_iter"), target, param, error_argument, out may_fail); // TODO check that parameter is not NULL (out parameters are optional) // free value if parameter is NULL @@ -829,7 +838,7 @@ public class Vala.GDBusClientModule : GDBusModule { } } - if (may_fail) { + if (may_fail && has_error_argument) { ccode.open_if (new CCodeBinaryExpression (CCodeBinaryOperator.AND, new CCodeIdentifier ("error"), new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("error")))); ccode.add_expression (unref_reply); return_default_value (m.return_type); diff --git a/tests/dbus/enum-string-marshalling.vala b/tests/dbus/enum-string-marshalling.vala index 14942a3f5..2cc764852 100644 --- a/tests/dbus/enum-string-marshalling.vala +++ b/tests/dbus/enum-string-marshalling.vala @@ -8,7 +8,8 @@ public interface Test : GLib.Object { public abstract async void test1 (FooEnum e) throws DBusError; public abstract void test2 (FooEnum e) throws DBusError; public abstract void test3 (FooEnum e1, UnixOutputStream output_stream, FooEnum e2) throws DBusError; - //FIXME public abstract void test4 (FooEnum e); + public abstract void test4 (FooEnum e); + public abstract async void test5 (FooEnum e); } void main () {