glib2/gdbus - arrays and g_variant_get() quirks

David Sommerseth <[email protected]>
Newsgroups gmane.comp.freedesktop.dbus
Message-ID <[email protected]>
Hi,

I'm getting quite puzzled when trying to extract an array using
g_variant_get() ... and I don't quite follow why this happens.

Lets first look at this little and simple snippet:

---------------------------------------------------------------------
     GVariant *res = some_function_returning_int_array_via_dbus();
     printf("Format (res): %s\n", g_variant_get_type_string(res));

     GVariant *array = NULL;
     g_variant_get(res, "(*)", &array);
     printf("Format (array): %s\n", g_variant_get_type_string(array));
---------------------------------------------------------------------

When running this little snippet the output is:

     Format (res): (au)
     Format (array): au

But I'm not really happy about the '(*)'.  So I change that to say:

     g_variant_get(res, "(au)", &array);

To my understanding, that should match the signature of the data.  But
this explodes:

     Format (res): (au)
     **
     GLib:ERROR:gvarianttypeinfo.c:163:g_variant_type_info_check:
assertion failed: (info->alignment == 0 || info->alignment == 1 ||
info->alignment == 3 || info->alignment == 7)
     Aborted


In pure desperation, I try to use the type 'au' instead.  But that
doesn't resolve it either:

     Format (res): (au)

     (process:27844): GLib-CRITICAL **: the GVariant format string 'au'
has a type of 'au' but the given value has a type of '(au)'

     (process:27844): GLib-CRITICAL **: g_variant_get: assertion
'valid_format_string (format_string, TRUE, value)' failed

     (process:27844): GLib-CRITICAL **: g_variant_get_type_string:
assertion 'value != NULL' failed
     Format (array): (null)


So there is obviously something I do not fully understand.  I do know
that results from D-Bus are inside a "container", so the ()
encapsulation is needed.  And I can easily extract data of other types
than arrays, dictionaries or tuples.  And as it works with the '(*)'
type; why not '(au)'?

What is the most appropriate and correct way to extract an array with
glib2/gdbus?


-- 
kind regards,

David Sommerseth
_______________________________________________
dbus mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dbus
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.