[Vala] async D-Bus methods that return arrays fail to compile


the following example program fails to compile because Vala adds the
length of the int[] output array (output_length1) to the async begin
function call instead of to the async finish function call. The async
function itself is fine, only the D-Bus wrappers put this parameter in
the wrong place. Is there any way to work around this for now?

[DBus (name = "org.example.Async")]
class AsyncTest : GLib.Object {
        public async void split_integer (int input, out int[] output) {
                int result[2];
                result[0] = input / 2;
                result[1] = input - result[0];
                output = result;
int main (string[] args) {
        var loop = new GLib.MainLoop (null, false);
        try {
                var connection = DBus.Bus.get (DBus.BusType.SESSION);
                dynamic DBus.Object bus = connection.get_object
("org.freedesktop.DBus", "/org/freedesktop/DBus",
                uint result = bus.request_name ("org.example.Async", (uint) 0);
                if (result == DBus.RequestNameReply.PRIMARY_OWNER) {
                        var test = new AsyncTest ();
                        connection.register_object ("/org/example/async", test);
                        loop.run ();
                } else {
                        error ("Failed to request name");
        } catch (DBus.Error e) {
                error ("Failed to get DBus object: %s", e.message);
        return 0;

Vala doesn't complain, but the resulting C code does not compile:

$ valac async-out-array.vala --pkg dbus-glib-1 --pkg gio-2.0 --save-temps
async-out-array.vala:3.2-3.32: warning: method
`AsyncTest.split_integer' never used
        public async void split_integer (int input, out int[] output) {
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c: In function
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:242: error:
‘output_length1’ undeclared (first use in this function)
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:242: error:
(Each undeclared identifier is reported only once
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:242: error:
for each function it appears in.)
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:242: error:
too many arguments to function ‘async_test_split_integer’
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c: In function
warning: passing argument 1 of ‘async_test_split_integer_finish’ from
incompatible pointer type
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:107: note:
expected ‘struct AsyncTest *’ but argument is of type ‘struct GObject
/home/ph5/src/vala/dbus/async-out-array/async-out-array.c:262: error:
too few arguments to function ‘async_test_split_integer_finish’
error: cc exited with status 256
Compilation failed: 1 error(s), 1 warning(s)

Partial C code result - you can see that
_dbus_async_test_split_integer tries to call async_test_split_integer
with the &output_length1 parameter, and that
_dbus_async_test_split_integer_ready is missing the &output_length1
parameter to async_test_split_integer_finish.

void async_test_split_integer (AsyncTest* self, gint input,
GAsyncReadyCallback _callback_, gpointer _user_data_);
void async_test_split_integer_finish (AsyncTest* self, GAsyncResult*
_res_, gint** output, int* output_length1);
static DBusHandlerResult _dbus_async_test_split_integer (AsyncTest*
self, DBusConnection* connection, DBusMessage* message) {
        DBusMessageIter iter;
        gint input = 0;
        dbus_int32_t _tmp1_;
        gpointer * _user_data_;
        if (strcmp (dbus_message_get_signature (message), "i")) {
        dbus_message_iter_init (message, &iter);
        dbus_message_iter_get_basic (&iter, &_tmp1_);
        dbus_message_iter_next (&iter);
        input = _tmp1_;
        _user_data_ = g_new0 (gpointer, 2);
        _user_data_[0] = dbus_connection_ref (connection);
        _user_data_[1] = dbus_message_ref (message);
        async_test_split_integer (self, input, &output_length1,
_dbus_async_test_split_integer_ready, _user_data_);
static void _dbus_async_test_split_integer_ready (GObject *
source_object, GAsyncResult * _res_, gpointer * _user_data_) {
        DBusConnection * connection;
        DBusMessage * message;
        DBusMessageIter iter;
        GError* error;
        gint* output = NULL;
        int output_length1;
        DBusMessage* reply;
        gint* _tmp2_;
        DBusMessageIter _tmp3_;
        int _tmp4_;
        connection = _user_data_[0];
        message = _user_data_[1];
        error = NULL;
        output_length1 = 0;
        async_test_split_integer_finish (source_object, _res_, &output);
        reply = dbus_message_new_method_return (message);
        dbus_message_iter_init_append (reply, &iter);
        _tmp2_ = output;
        dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "i", &_tmp3_);
        for (_tmp4_ = 0; _tmp4_ < output_length1; _tmp4_++) {
                dbus_int32_t _tmp5_;
                _tmp5_ = *_tmp2_;
                dbus_message_iter_append_basic (&_tmp3_, DBUS_TYPE_INT32, &_tmp5_);
        dbus_message_iter_close_container (&iter, &_tmp3_);
        output = (g_free (output), NULL);
        dbus_connection_send (connection, reply, NULL);
        dbus_message_unref (reply);
        dbus_connection_unref (connection);
        dbus_message_unref (message);
        g_free (_user_data_);


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