new API to deconstruct a variant in one step
Submitted by Allison (desrt)
Assigned to Allison (desrt)
Link to original bug (#697378)
Description
The first patch in bug 697154 shows the bad things that can happen when people try to handle the relatively common case of extracting a value of an expected type from a 'v'.
We have convenience APIs to properly handle this in the case of 'a{sv}' but not just a plain 'v'.
Ideally this API would be called g_variant_get_variant() (with the existing function of that name called g_variant_get_variant_value()) but since the name is already taken, maybe we could call it g_variant_get_from_variant().
Would work like so:
v = (some 'v' type GVariant presumably containing a string);
const gchar *str;
if (g_variant_get_from_variant (v, "&s", &str)) { ..it worked.. } else .. 'v' didn't contain a string ..
This lets you do the process of unpacking the variant, checking its type, performing further deconstruction and unreffing the intermediate variant in just one step.