1

The following simple code is sufficient to reproduce the error I am having.

#include <gio/gio.h>

int main()
{
    GVariantIter *Iter;
    const gchar* s = "[('appname', uint64 size, uint64 field, false)]";
    GVariant* up = g_variant_new_string(s);
    Iter = g_variant_iter_new(up);
    return 0;
}

It is resulting in:

GLib:ERROR:../../../glib/gvariant-serialiser.c:1367:g_variant_serialised_n_children: code should not be reached Bail out! GLib:ERROR:../../../glib/gvariant-serialiser.c:1367:g_variant_serialised_n_children: code should not be reached Aborted

What am I missing? The documentation is somewhat vague.

g_variant_new_string ()

GVariant * g_variant_new_string (const gchar *string);
Creates a string GVariant with the contents of string.

g_variant_iter_new ()

GVariantIter * g_variant_iter_new (GVariant *value);
Creates a heap-allocated GVariantIter for iterating over the items in value.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tony Tannous
  • 14,154
  • 10
  • 50
  • 86
  • 1
    I barely used `GVariants` so far... but isn't it supposed to be a container that you create an iterator for? I don't think you can iterate over a string. – Gerhardh Jan 19 '22 at 12:27
  • 1
    Precisely, `GVariantIter` is for iterating over containers (arrays, dictionaries and tuples). What did you think iterating over a string would do? – Philip Withnall Jan 19 '22 at 14:11
  • @PhilipWithnall the string I am receiving is an actual array. I provided a dummy example. The one I get is in the format: `[('appname', uint64 size, uint64 field, gboolean)]` I was hoping instead of breaking the raw string, to create a GVariant to iter over it. – Tony Tannous Jan 19 '22 at 15:57
  • 1
    If the string is in the format exported by `g_variant_print()`, then you can use `g_variant_parse()` to parse it into a `GVariant*`. Without a minimal reproducer of the code you’re trying to get working then I can’t be sure, though. – Philip Withnall Jan 20 '22 at 15:04

0 Answers0