[glib/gvariant] remove oddity with g_variant_type_new_tuple



commit d156078711f4aef4cfee9e0b3e0e983ded86307c
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 14 21:52:23 2010 -0500

    remove oddity with g_variant_type_new_tuple

 glib/glib.symbols    |    2 +-
 glib/gvariant-util.c |   13 ++++++++++---
 glib/gvarianttype.c  |   49 +++++++++----------------------------------------
 glib/gvarianttype.h  |   10 ++--------
 4 files changed, 22 insertions(+), 52 deletions(-)
---
diff --git a/glib/glib.symbols b/glib/glib.symbols
index ed4f9ed..b8ca76e 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1783,7 +1783,7 @@ g_variant_type_key
 g_variant_type_value
 g_variant_type_new_array
 g_variant_type_new_maybe
-g_variant_type_new_tuple_
+g_variant_type_new_tuple
 g_variant_type_new_dict_entry
 g_variant_type_check_string_
 #endif
diff --git a/glib/gvariant-util.c b/glib/gvariant-util.c
index 941848f..b44bdf9 100644
--- a/glib/gvariant-util.c
+++ b/glib/gvariant-util.c
@@ -1278,9 +1278,16 @@ g_variant_builder_end (GVariantBuilder *builder)
         break;
 
       case G_VARIANT_TYPE_CLASS_TUPLE:
-        my_type = g_variant_type_new_tuple (builder->children,
-                                            g_variant_get_type,
-                                            builder->offset);
+        {
+          const GVariantType **types;
+          gint i;
+
+          types = g_new (const GVariantType *, builder->offset);
+          for (i = 0; i < builder->offset; i++)
+            types[i] = g_variant_get_type (builder->children[i]);
+          my_type = g_variant_type_new_tuple (types, i);
+          g_free (types);
+        }
         break;
 
       default:
diff --git a/glib/gvarianttype.c b/glib/gvarianttype.c
index 8a908b0..650d72a 100644
--- a/glib/gvarianttype.c
+++ b/glib/gvarianttype.c
@@ -842,41 +842,19 @@ g_variant_type_value (const GVariantType *type)
 }
 
 /**
- * GVariantTypeGetter:
- * @data: a pointer
- * @returns: a const #GVariantType
- *
- * A callback function intended for use with
- * g_variant_type_new_tuple().  This function's purpose is to extract
- * a #GVariantType from some pointer type.  The returned type should
- * be owned by whatever is at the end of the pointer because it won't
- * be freed.
- **/
-/**
  * g_variant_type_new_tuple:
- * @items: an array of items, one for each item
- * @func: a function to determine each item type
+ * @items: an array of #GVariantTypes, one for each item
  * @length: the length of @items
  * @returns: a new #GVariantType
  *
- * Constructs a new tuple type.
- *
- * The item types for the tuple type may be provided directly (as
- * an array of #GVariantType), in which case @func should be %NULL.
- *
- * The item types can also be provided indirectly.  In this case,
- * @items should be an array of pointers which are passed one at a
- * time to @func to determine the corresponding #GVariantType.  For
- * example, you might provide an array of #GVariant pointers for
- * @items and g_variant_get_type() for @func.
+ * Constructs a new tuple type, from @items.
  *
  * The result of this function must be freed with a call to
  * g_variant_type_free().
  **/
 static GVariantType *
-g_variant_type_new_tuple_slow (const gpointer     *items,
-                               GVariantTypeGetter  func,
-                               gsize               length)
+g_variant_type_new_tuple_slow (const GVariantType * const *items,
+                               gint                        length)
 {
   GString *string;
   gsize i;
@@ -887,11 +865,7 @@ g_variant_type_new_tuple_slow (const gpointer     *items,
       const GVariantType *type;
       gsize size;
 
-      if (func)
-        type = func (items[i]);
-      else
-        type = items[i];
-
+      type = items[i];
       size = g_variant_type_get_string_length (type);
       g_string_append_len (string, (const gchar *) type, size);
     }
@@ -901,9 +875,8 @@ g_variant_type_new_tuple_slow (const gpointer     *items,
 }
 
 GVariantType *
-g_variant_type_new_tuple_ (const gpointer     *items,
-                           GVariantTypeGetter  func,
-                           gsize               length)
+g_variant_type_new_tuple (const GVariantType * const *items,
+                          gint                        length)
 {
   char buffer[1024];
   gsize offset;
@@ -925,15 +898,11 @@ g_variant_type_new_tuple_ (const gpointer     *items,
       const GVariantType *type;
       gsize size;
 
-      if (func)
-        type = func (items[i]);
-      else
-        type = items[i];
-
+      type = items[i];
       size = g_variant_type_get_string_length (type);
 
       if (offset + size >= sizeof buffer) /* leave room for ')' */
-        return g_variant_type_new_tuple_slow (items, func, length);
+        return g_variant_type_new_tuple_slow (items, length);
 
       memcpy (&buffer[offset], type, size);
       offset += size;
diff --git a/glib/gvarianttype.h b/glib/gvarianttype.h
index 90d883b..2b61a0b 100644
--- a/glib/gvarianttype.h
+++ b/glib/gvarianttype.h
@@ -321,10 +321,8 @@ const GVariantType *            g_variant_type_value                    (const G
 /* constructors */
 GVariantType *                  g_variant_type_new_array                (const GVariantType  *element);
 GVariantType *                  g_variant_type_new_maybe                (const GVariantType  *element);
-typedef const GVariantType   *(*GVariantTypeGetter)                     (gpointer             data);
-GVariantType *                  g_variant_type_new_tuple_               (const gpointer      *items,
-                                                                         GVariantTypeGetter   func,
-                                                                         gsize                length);
+GVariantType *                  g_variant_type_new_tuple                (const GVariantType * const *items,
+                                                                         gint                 length);
 GVariantType *                  g_variant_type_new_dict_entry           (const GVariantType  *key,
                                                                          const GVariantType  *value);
 
@@ -336,8 +334,4 @@ G_END_DECLS
 #define G_VARIANT_TYPE(type_string) \
   (g_variant_type_check_string_ (type_string))
 
-#define g_variant_type_new_tuple(items, func, length) \
-  (g_variant_type_new_tuple_ ((const gpointer *) items, (GVariantTypeGetter) (1 ? func : \
-                               (const GVariantType *(*)(typeof (items[0]))) NULL), length))
-
 #endif /* __G_VARIANT_TYPE_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]