glib2/gdbus - arrays and g_variant_get() quirks
David Sommerseth
dbus at lists.topphemmelig.net
Mon Oct 9 21:35:38 UTC 2017
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
More information about the dbus
mailing list