GVariant: clean up serialised data handling API
authorRyan Lortie <desrt@desrt.ca>
Sat, 29 Nov 2014 20:58:49 +0000 (15:58 -0500)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Fri, 10 Jul 2015 09:47:43 +0000 (11:47 +0200)
commit1a3783987be7aa436c4b0789ce019289773d5018
treec1d077096c3a681201dc5c159dfcc53805ea100f
parent904ec5534cdc45d9b90e86a467e97af3b1bdd66d
GVariant: clean up serialised data handling API

Add a new pair of internal helpers to gvariant-core.c to provide a
unified way to construct and query the content of serialised GVariant
instances.

Rewrite g_variant_new_from_data() to use this.

Move g_variant_new_from_bytes() and g_variant_get_data_as_bytes() out of
-core and into gvariant.c, also rewriting them to use the same.

Take the time to do some cleanup and make some general improvements in
consistency:

 - move the checks for improperly sized fixed-sized data out of
   _new_from_bytes() and into the common code so that we do this check
   on _new_from_data() as well

 - correctly deal with the case of NULL data in _get_data_as_bytes().
   This would have crashed before.  Add a test for that.

 - if the user hands us data with a size of zero then unref and/or
   destroy-notify things immediately.

The idea that every GVariant must have an associated GBytes remains.
This could potentially be optimsed a bit further in the future, but the
cases where it could be avoided are only a few (errors, zero-size,
static stoarge) so let's not pursue that now.
glib/gvariant-core.c
glib/gvariant-core.h
glib/gvariant.c
glib/tests/gvariant.c