Add g_variant_is_floating

This commit is contained in:
Christian Persch 2010-06-19 16:42:11 +02:00
parent 7bb00fd0e8
commit 052ef2614a
5 changed files with 40 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -674,6 +674,30 @@ g_variant_ref_sink (GVariant *value)
return 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

View File

@ -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);

View File

@ -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 ();
}