From 052ef2614af7a8706035982d8211fff64241e83f Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Sat, 19 Jun 2010 16:42:11 +0200 Subject: [PATCH] Add g_variant_is_floating --- docs/reference/glib/glib-sections.txt | 1 + glib/glib.symbols | 1 + glib/gvariant-core.c | 24 ++++++++++++++++++++++++ glib/gvariant.h | 1 + glib/tests/gvariant.c | 13 +++++++++++++ 5 files changed, 40 insertions(+) diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index ec4892d..026fc39 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -2808,6 +2808,7 @@ GVariant g_variant_unref g_variant_ref g_variant_ref_sink +g_variant_is_floating g_variant_get_type g_variant_get_type_string g_variant_is_of_type diff --git a/glib/glib.symbols b/glib/glib.symbols index cb1318f..41ef82b 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -1710,6 +1710,7 @@ g_variant_type_checked_ g_variant_unref g_variant_ref g_variant_ref_sink +g_variant_is_floating g_variant_n_children g_variant_get_child_value g_variant_get_size diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c index e3597e4..2b8caa5 100644 --- a/glib/gvariant-core.c +++ b/glib/gvariant-core.c @@ -675,6 +675,30 @@ g_variant_ref_sink (GVariant *value) } /** + * g_variant_is_floating: + * @value: a #GVariant + * @returns: whether @value is floating + * + * Checks whether @value has a floating reference count. + * + * This function should only ever be used to assert that a given variant + * is or is not floating, or for debug purposes. To acquire a reference + * to a variant that might be floating, always use g_variant_ref_sink(). + * + * See g_variant_ref_sink() for more information about floating reference + * counts. + * + * Since: 2.26 + **/ +gboolean +g_variant_is_floating (GVariant *value) +{ + g_return_val_if_fail (value != NULL, FALSE); + + return (value->state & STATE_FLOATING) != 0; +} + +/** * g_variant_get_size: * @value: a #GVariant instance * @returns: the serialised size of @value diff --git a/glib/gvariant.h b/glib/gvariant.h index e4a80c0..6647c40 100644 --- a/glib/gvariant.h +++ b/glib/gvariant.h @@ -55,6 +55,7 @@ typedef enum void g_variant_unref (GVariant *value); GVariant * g_variant_ref (GVariant *value); GVariant * g_variant_ref_sink (GVariant *value); +gboolean g_variant_is_floating (GVariant *value); const GVariantType * g_variant_get_type (GVariant *value); const gchar * g_variant_get_type_string (GVariant *value); diff --git a/glib/tests/gvariant.c b/glib/tests/gvariant.c index 68c6ec4..23302f8 100644 --- a/glib/tests/gvariant.c +++ b/glib/tests/gvariant.c @@ -3800,6 +3800,18 @@ test_parse_positional (void) } } +static void +test_floating (void) +{ + GVariant *value; + + value = g_variant_new_int32 (42); + g_assert (g_variant_is_floating (value)); + g_variant_ref_sink (value); + g_assert (!g_variant_is_floating (value)); + g_variant_unref (value); +} + int main (int argc, char **argv) { @@ -3838,6 +3850,7 @@ main (int argc, char **argv) g_test_add_func ("/gvariant/parser", test_parses); g_test_add_func ("/gvariant/parse-failures", test_parse_failures); g_test_add_func ("/gvariant/parse-positional", test_parse_positional); + g_test_add_func ("/gvariant/floating", test_floating); return g_test_run (); } -- 2.7.4