[glib/gvariant] update GVariant varargs code to match docs
- From: Ryan Lortie <ryanl src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [glib/gvariant] update GVariant varargs code to match docs
- Date: Thu, 7 Jan 2010 18:20:27 +0000 (UTC)
commit baca6adaff5a9002ad8e716c3919e2ac41853538
Author: Ryan Lortie <desrt desrt ca>
Date: Thu Jan 7 13:20:08 2010 -0500
update GVariant varargs code to match docs
glib/gvariant-valist.c | 30 +++++++++++++++---------------
glib/gvariant.h | 2 ++
glib/tests/gvariant-varargs.c | 21 +++++++++++----------
3 files changed, 28 insertions(+), 25 deletions(-)
---
diff --git a/glib/gvariant-valist.c b/glib/gvariant-valist.c
index 747b577..58b8e39 100644
--- a/glib/gvariant-valist.c
+++ b/glib/gvariant-valist.c
@@ -385,16 +385,6 @@ g_variant_valist_new (const gchar **format_string,
g_variant_new_variant (value));
break;
- case 'a':
- {
- GVariantBuilder *array;
-
- if ((array = va_arg (*app, GVariantBuilder *)))
- g_variant_builder_add_value (builder,
- g_variant_builder_end (array));
- break;
- }
-
case '&':
{
gconstpointer ptr;
@@ -425,15 +415,23 @@ g_variant_valist_new (const gchar **format_string,
default:
{
- gboolean just;
+ gboolean *just;
- just = va_arg (*app, gboolean);
+ just = va_arg (*app, gboolean *);
- if (just)
+ if (just != NULL)
{
+ /* non-NULL, so consume the arguments */
value = g_variant_valist_new (&string, app);
- g_variant_builder_add_value (builder, value);
g_assert (string == *format_string);
+
+ g_variant_ref_sink (value);
+
+ if (*just)
+ /* only put in the maybe if just was TRUE */
+ g_variant_builder_add_value (builder, value);
+
+ g_variant_unref (value);
}
}
}
@@ -827,12 +825,14 @@ g_variant_valist_get (GVariant *value,
just = NULL;
/* skip the 'm', check the next character */
- if (!strchr ("sogv *?ra&", *++(*format_string)))
+ if (!strchr ("sogv *?r&", *++(*format_string)))
{
gboolean *ptr = va_arg (*app, gboolean *);
if (ptr)
{
+ /* only free the args if *ptr was TRUE from last time.
+ * else, last iteration was 'None' -> nothing to free. */
g_variant_valist_get (just, free && *ptr,
format_string, app);
*ptr = just != NULL;
diff --git a/glib/gvariant.h b/glib/gvariant.h
index 83ec437..478be9a 100644
--- a/glib/gvariant.h
+++ b/glib/gvariant.h
@@ -256,6 +256,8 @@ void g_variant_store (GVarian
gconstpointer g_variant_get_data (GVariant *value);
gsize g_variant_get_size (GVariant *value);
+#define G_VARIANT_JUST ((gboolean *) "truetrue")
+
G_END_DECLS
#endif /* __G_VARIANT_H__ */
diff --git a/glib/tests/gvariant-varargs.c b/glib/tests/gvariant-varargs.c
index 5a6b1d7..3ada330 100644
--- a/glib/tests/gvariant-varargs.c
+++ b/glib/tests/gvariant-varargs.c
@@ -35,7 +35,7 @@ make_value (void)
g_variant_builder_add (array, "(bym(nquisv)xtd? s@?* *r@r&(bqutd)"
"&a(bqutd)msmvm*m?m sm@*anmanm&(bqutd))",
TRUE, 0x8c,
- TRUE, 0x1316, 0xccff, -344763333, 0xf77f5aa5,
+ G_VARIANT_JUST, 0x1316, 0xccff, -344763333, 0xf77f5aa5,
"crikey!!", g_variant_new_int32 (-11111111),
G_GINT64_CONSTANT (0x123),
G_GUINT64_CONSTANT (0xaabbccddeeff),
@@ -47,19 +47,19 @@ make_value (void)
g_variant_new_object_path ("/usr/local"),
g_variant_new ("()"),
g_variant_new ("(bbb)", TRUE, FALSE, TRUE),
- fixed_struct, fixed_struct, 3,
+ fixed_struct, fixed_struct, (gsize) 3,
"i'm gone",
g_variant_new_uint16 (44444),
g_variant_new_uint16 (22222),
g_variant_new_int16 (-7777),
g_variant_new_string ("this is getting insane"),
g_variant_new_string ("ugh"),
- ebuilder1, builder, fixed_struct, 72727);
+ ebuilder1, G_VARIANT_JUST, builder, fixed_struct);
g_variant_builder_add (array, "(bym(nquisv)xtd? s@?* *r@r&(bqutd)"
"&a(bqutd)msmvm qm@nm sm@sanmanm&(bqutd))",
TRUE, 0x8c,
- FALSE,
+ NULL,
G_GINT64_CONSTANT (0x123),
G_GUINT64_CONSTANT (0xaabbccddeeff),
1234.75,
@@ -77,7 +77,7 @@ make_value (void)
g_variant_builder_add (array, "(bym(nquisv)xtd? s@?* *r@r&(bqutd)"
"&a(bqutd)msmvm qm@nm sm@sanmanm&(bqutd))",
TRUE, 0x8c,
- FALSE,
+ NULL,
G_GINT64_CONSTANT (0x123),
G_GUINT64_CONSTANT (0xaabbccddeeff),
1234.75,
@@ -92,14 +92,14 @@ make_value (void)
NULL, NULL, NULL, NULL, NULL, NULL,
ebuilder3, NULL, NULL);
- return g_variant_builder_end (array);
+ return g_variant_ref_sink (g_variant_builder_end (array));
}
static void
test_iterate (void)
{
GVariant *maybe_one, *maybe_two, *maybe_three, *maybe_four, *maybe_five;
- GVariant *one, *two, *three, *four, *five, *six, *seven = (gpointer) 0xcccccccc, *eight;
+ GVariant *one, *two, *three, *four, *five, *six, *seven, *eight;
struct structure *fixed_array; gint fixed_array_size;
struct structure *maybe_fixed_struct, *fixed_struct;
const gchar *string, *maybe_string;
@@ -108,8 +108,8 @@ test_iterate (void)
guint16 uint16; gint16 int16;
guint32 uint32; gint32 int32;
guint64 uint64; gint64 int64;
+ gboolean is_just, have_array;
gdouble floating;
- gboolean is_just;
GVariantIter iter;
gboolean first;
@@ -140,7 +140,8 @@ test_iterate (void)
&maybe_string, &maybe_one, &maybe_two,
&maybe_three, &maybe_four, &maybe_five,
- &array, &maybe_array, &maybe_fixed_struct))
+ &array, &have_array, &maybe_array,
+ &maybe_fixed_struct))
{
g_assert_cmpint (boolean, ==, TRUE);
g_assert_cmpint (byte, ==, 0x8c);
@@ -189,7 +190,7 @@ test_iterate (void)
g_assert_cmpint ((maybe_four != NULL), ==, first);
g_assert_cmpint ((maybe_five != NULL), ==, first);
g_assert_cmpint (g_variant_iter_was_cancelled (&array), ==, FALSE);
- g_assert_cmpint (g_variant_iter_was_cancelled (&maybe_array), !=, first);
+ g_assert_cmpint (have_array, ==, first);
g_assert_cmpint ((maybe_fixed_struct != NULL), ==, first);
if (first)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]