[vala/0.34] codegen: Check there is a return error location before using it
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.34] codegen: Check there is a return error location before using it
- Date: Mon, 6 Mar 2017 14:43:43 +0000 (UTC)
commit 41e7279b5970040c70c8e542f4a96646bdc260a0
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Mar 6 14:23:19 2017 +0100
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
codegen/valagdbusclientmodule.vala | 21 +++++++++++++++------
tests/dbus/enum-string-marshalling.vala | 3 ++-
2 files changed, 17 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valagdbusclientmodule.vala b/codegen/valagdbusclientmodule.vala
index e1a53fb..40d97e9 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"));
@@ -721,7 +729,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);
}
@@ -740,7 +748,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);
@@ -787,7 +795,8 @@ public class Vala.GDBusClientModule : GDBusModule {
var target = new CCodeIdentifier ("_vala_" + 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
@@ -800,7 +809,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 14942a3..2cc7648 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 () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]