[glib/gvariant] simplify GVariantBuilder implementation



commit e85b19979018c73aae987b8d84eb7fd1d261d8ac
Author: Ryan Lortie <desrt desrt ca>
Date:   Thu Jan 21 14:17:20 2010 -0500

    simplify GVariantBuilder implementation
    
    use GVariantType more directly, remove old uses of GVariantTypeClass

 glib/glib.symbols          |   13 +-
 glib/gvariant-core.c       |   20 ++-
 glib/gvariant-markup.c     |   78 +++---
 glib/gvariant-parser.c     |   36 ++--
 glib/gvariant-printer.c    |   38 ++--
 glib/gvariant-serialiser.c |   86 ++++----
 glib/gvariant-util.c       |  569 ++++++++++++++++----------------------------
 glib/gvariant-valist.c     |    3 +-
 glib/gvariant.h            |    3 +-
 glib/gvarianttype.c        |  191 ++++------------
 glib/gvarianttype.h        |  114 +++------
 glib/gvarianttypeinfo.c    |   48 ++--
 glib/gvarianttypeinfo.h    |    2 +-
 glib/tests/gvariant-big.c  |   32 ++--
 14 files changed, 469 insertions(+), 764 deletions(-)
---
diff --git a/glib/glib.symbols b/glib/glib.symbols
index b8ca76e..2ee1333 100644
--- a/glib/glib.symbols
+++ b/glib/glib.symbols
@@ -1662,12 +1662,12 @@ g_variant_get_fixed_array
 g_variant_get_child_value
 g_variant_n_children
 g_variant_get_type
+g_variant_classify
 #endif
 
 #if IN_FILE(__G_VARIANT_UTIL_C__)
 g_variant_from_file
 g_variant_flatten
-g_variant_get_type_class
 g_variant_get_type_string
 g_variant_is_basic
 g_variant_is_container
@@ -1768,13 +1768,13 @@ g_variant_type_dup_string
 g_variant_type_is_concrete
 g_variant_type_is_container
 g_variant_type_is_basic
+g_variant_type_is_maybe
+g_variant_type_is_array
+g_variant_type_is_tuple
+g_variant_type_is_dict_entry
 g_variant_type_hash
 g_variant_type_equal
 g_variant_type_is_subtype_of
-g_variant_type_is_in_class
-g_variant_type_get_class
-g_variant_type_class_is_container
-g_variant_type_class_is_basic
 g_variant_type_element
 g_variant_type_first
 g_variant_type_next
@@ -1785,14 +1785,13 @@ g_variant_type_new_array
 g_variant_type_new_maybe
 g_variant_type_new_tuple
 g_variant_type_new_dict_entry
-g_variant_type_check_string_
 #endif
 #endif
 
 #if IN_HEADER(__G_VARIANT_TYPE_INFO_H__)
 #if IN_FILE(__G_VARIANT_TYPE_INFO_C__)
 g_variant_type_info_get_type
-g_variant_type_info_get_type_class
+g_variant_type_info_get_class
 g_variant_type_info_get_string
 g_variant_type_info_query
 g_variant_type_info_element
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index 8fd6c76..4e2972c 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -672,7 +672,7 @@ g_variant_load_fixed (const GVariantType *type,
   GVariant *new;
 
   info = g_variant_type_info_get (type);
-  if (g_variant_type_is_in_class (type, G_VARIANT_TYPE_CLASS_ARRAY))
+  if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_ARRAY))
     {
       g_variant_type_info_query_element (info, NULL, &fixed_size);
       fixed_size *= n_items;
@@ -858,7 +858,7 @@ g_variant_apply_flags (GVariant      *value,
   if (byte_order == G_BYTE_ORDER)
     value->state |= CONDITION_NATIVE;
 
-  else if (!flags & G_VARIANT_LAZY_BYTESWAP)
+  else if (~flags & G_VARIANT_LAZY_BYTESWAP)
     g_variant_require_conditions (value, CONDITION_NATIVE);
 
   g_variant_assert_invariant (value);
@@ -1478,5 +1478,21 @@ g_variant_load (const GVariantType *type,
     }
 }
 
+/**
+ * g_variant_classify:
+ * @value: a #GVariant
+ * @returns: the #GVariantClass of @value
+ *
+ * Returns the type class of @value.  This function is equivalent to
+ * calling g_variant_get_type() followed by
+ * g_variant_type_get_class().
+ **/
+GVariantClass
+g_variant_classify (GVariant *value)
+{
+  g_return_val_if_fail (value != NULL, 0);
+  return g_variant_type_info_get_class (value->type);
+}
+
 #define __G_VARIANT_CORE_C__
 #include "galiasdef.c"
diff --git a/glib/gvariant-markup.c b/glib/gvariant-markup.c
index 1c2ee79..84c9afb 100644
--- a/glib/gvariant-markup.c
+++ b/glib/gvariant-markup.c
@@ -122,9 +122,9 @@ g_variant_markup_print_string (GVariant *value,
   g_variant_markup_indent (string, indentation);
   indentation += tabstop;
 
-  switch (g_variant_get_type_class (value))
+  switch (g_variant_classify (value))
   {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariant *child;
 
@@ -142,7 +142,7 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         if (g_variant_n_children (value))
           {
@@ -166,7 +166,7 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         GVariantIter iter;
 
@@ -191,7 +191,7 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
+    case G_VARIANT_CLASS_TUPLE:
       {
         GVariantIter iter;
 
@@ -215,7 +215,7 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         GVariantIter iter;
         GVariant *element;
@@ -234,7 +234,7 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       {
         const gchar *str;
         char *escaped;
@@ -266,64 +266,64 @@ g_variant_markup_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BOOLEAN:
       if (g_variant_get_boolean (value))
         g_string_append (string, "<true/>");
       else
         g_string_append (string, "<false/>");
       break;
 
-    case G_VARIANT_TYPE_CLASS_BYTE:
+    case G_VARIANT_CLASS_BYTE:
       g_string_append_printf (string, "<byte>0x%02x</byte>",
                               g_variant_get_byte (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT16:
+    case G_VARIANT_CLASS_INT16:
       g_string_append_printf (string, "<int16>%"G_GINT16_FORMAT"</int16>",
                               g_variant_get_int16 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT16:
+    case G_VARIANT_CLASS_UINT16:
       g_string_append_printf (string, "<uint16>%"G_GUINT16_FORMAT"</uint16>",
                               g_variant_get_uint16 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT32:
+    case G_VARIANT_CLASS_INT32:
       g_string_append_printf (string, "<int32>%"G_GINT32_FORMAT"</int32>",
                               g_variant_get_int32 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_HANDLE:
+    case G_VARIANT_CLASS_HANDLE:
       g_string_append_printf (string, "<handle>%"G_GINT32_FORMAT"</handle>",
                               g_variant_get_handle (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT32:
+    case G_VARIANT_CLASS_UINT32:
       g_string_append_printf (string, "<uint32>%"G_GUINT32_FORMAT"</uint32>",
                               g_variant_get_uint32 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT64:
+    case G_VARIANT_CLASS_INT64:
       g_string_append_printf (string, "<int64>%"G_GINT64_FORMAT"</int64>",
                               g_variant_get_int64 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT64:
+    case G_VARIANT_CLASS_UINT64:
       g_string_append_printf (string, "<uint64>%"G_GUINT64_FORMAT"</uint64>",
                               g_variant_get_uint64 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_DOUBLE:
       g_string_append_printf (string, "<double>%f</double>",
                               g_variant_get_double (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_OBJECT_PATH:
       g_string_append_printf (string, "<object-path>%s</object-path>",
                               g_variant_get_string (value, NULL));
       break;
 
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_SIGNATURE:
       g_string_append_printf (string, "<signature>%s</signature>",
                               g_variant_get_string (value, NULL));
       break;
@@ -584,7 +584,6 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
 {
   GVariantParseData *data = user_data;
   const GVariantType *type;
-  GVariantTypeClass class;
 
   if (data->terminal_value)
     {
@@ -593,9 +592,8 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
     }
 
   type = type_from_keyword (element_name);
-  class = g_variant_type_get_class (type);
 
-  if (g_variant_type_class_is_basic (class))
+  if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_BASIC))
     {
       GVariant *value;
       char *string;
@@ -610,8 +608,8 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
           break;
 
       if G_UNLIKELY (i == data->string->len &&
-                     class != G_VARIANT_TYPE_CLASS_STRING &&
-                     class != G_VARIANT_TYPE_CLASS_SIGNATURE)
+                     !g_variant_type_equal (type, G_VARIANT_TYPE_STRING) &&
+                     !g_variant_type_equal (type, G_VARIANT_TYPE_SIGNATURE))
         {
           g_set_error (error, G_MARKUP_ERROR,
                        G_MARKUP_ERROR_INVALID_CONTENT,
@@ -622,49 +620,49 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
 
       string = &data->string->str[i];
 
-      switch (class)
-      {
-        case G_VARIANT_TYPE_CLASS_BOOLEAN:
+      switch (*(const gchar *)type)
+        {
+        case G_VARIANT_CLASS_BOOLEAN:
           value = g_variant_new_boolean (parse_bool (string, &end));
           break;
 
-        case G_VARIANT_TYPE_CLASS_BYTE:
+        case G_VARIANT_CLASS_BYTE:
           value = g_variant_new_byte (g_ascii_strtoll (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_INT16:
+        case G_VARIANT_CLASS_INT16:
           value = g_variant_new_int16 (g_ascii_strtoll (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_UINT16:
+        case G_VARIANT_CLASS_UINT16:
           value = g_variant_new_uint16 (g_ascii_strtoull (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_INT32:
+        case G_VARIANT_CLASS_INT32:
           value = g_variant_new_int32 (g_ascii_strtoll (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_HANDLE:
+        case G_VARIANT_CLASS_HANDLE:
           value = g_variant_new_handle (g_ascii_strtoll (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_UINT32:
+        case G_VARIANT_CLASS_UINT32:
           value = g_variant_new_uint32 (g_ascii_strtoull (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_INT64:
+        case G_VARIANT_CLASS_INT64:
           value = g_variant_new_int64 (g_ascii_strtoll (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_UINT64:
+        case G_VARIANT_CLASS_UINT64:
           value = g_variant_new_uint64 (g_ascii_strtoull (string, &end, 0));
           break;
 
-        case G_VARIANT_TYPE_CLASS_DOUBLE:
+        case G_VARIANT_CLASS_DOUBLE:
           value = g_variant_new_double (g_ascii_strtod (string, &end));
           break;
 
-        case G_VARIANT_TYPE_CLASS_STRING:
+        case G_VARIANT_CLASS_STRING:
           if (strcmp (element_name, "string") == 0)
             {
               value = g_variant_new_string (data->string->str);
@@ -684,7 +682,7 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
           end = NULL;
           break;
 
-        case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+        case G_VARIANT_CLASS_OBJECT_PATH:
           if (!g_variant_is_object_path (data->string->str))
             {
               g_set_error (error, G_MARKUP_ERROR,
@@ -696,7 +694,7 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
           end = NULL;
           break;
 
-        case G_VARIANT_TYPE_CLASS_SIGNATURE:
+        case G_VARIANT_CLASS_SIGNATURE:
           if (!g_variant_is_signature (data->string->str))
             {
               g_set_error (error, G_MARKUP_ERROR,
@@ -710,7 +708,7 @@ g_variant_markup_parser_end_element (GMarkupParseContext  *context,
 
         default:
           g_assert_not_reached ();
-      }
+        }
 
       /* ensure only trailing whitespace */
       for (i = 0; end && end[i]; i++)
diff --git a/glib/gvariant-parser.c b/glib/gvariant-parser.c
index eb1248f..fbf1572 100644
--- a/glib/gvariant-parser.c
+++ b/glib/gvariant-parser.c
@@ -238,7 +238,7 @@ type_from_constraints (Constraints constraints)
       if (constraints & (CONSTRAINT_IS_NUMBER | CONSTRAINT_IS_BOOLEAN))
         return 0;
 
-      return G_VARIANT_TYPE_CLASS_STRING;
+      return G_VARIANT_CLASS_STRING;
     }
 
   if (constraints & CONSTRAINT_IS_BOOLEAN)
@@ -246,13 +246,13 @@ type_from_constraints (Constraints constraints)
       if (constraints & CONSTRAINT_IS_NUMBER)
         return 0;
 
-      return G_VARIANT_TYPE_CLASS_BOOLEAN;
+      return G_VARIANT_CLASS_BOOLEAN;
     }
   
   if (constraints & CONSTRAINT_HAS_POINT)
-    return G_VARIANT_TYPE_CLASS_DOUBLE;
+    return G_VARIANT_CLASS_DOUBLE;
 
-  return G_VARIANT_TYPE_CLASS_INT32;
+  return G_VARIANT_CLASS_INT32;
 }
 
 typedef struct
@@ -333,7 +333,7 @@ pattern_coalesce (Pattern       *dest,
 }
 
 static Pattern *
-pattern_from_class (GVariantTypeClass class)
+pattern_from_class (GVariantClass class)
 {
   Pattern *pattern;
 
@@ -883,7 +883,7 @@ static Pattern *
 variant_get_pattern (AST                *ast,
                      GVariantParseError *error)
 {
-  return pattern_from_class (G_VARIANT_TYPE_CLASS_VARIANT);
+  return pattern_from_class (G_VARIANT_CLASS_VARIANT);
 }
 
 static GVariant *
@@ -1440,16 +1440,16 @@ terminal_get_value (AST                *ast,
 {
   Terminal *terminal = (Terminal *) ast;
 
-  switch (g_variant_type_get_class (type))
+  switch (*(const gchar *) type)
     {
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BOOLEAN:
       {
         ast_set_error (ast, error,
                        "Unable to parse as boolean: %s", terminal->token);
         return NULL;
       }
 
-    case G_VARIANT_TYPE_CLASS_BYTE:
+    case G_VARIANT_CLASS_BYTE:
       if (terminal->string != NULL)
         {
           if (strlen (terminal->string) != 1)
@@ -1471,7 +1471,7 @@ terminal_get_value (AST                *ast,
           return g_variant_new_byte (value);
         }
 
-    case G_VARIANT_TYPE_CLASS_INT16:
+    case G_VARIANT_CLASS_INT16:
       {
         gint64 value;
 
@@ -1483,7 +1483,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_int16 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_UINT16:
+    case G_VARIANT_CLASS_UINT16:
       {
         guint64 value;
 
@@ -1495,7 +1495,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_uint16 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_INT32:
+    case G_VARIANT_CLASS_INT32:
       {
         gint64 value;
 
@@ -1507,7 +1507,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_int32 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_HANDLE:
+    case G_VARIANT_CLASS_HANDLE:
       {
         gint64 value;
 
@@ -1519,7 +1519,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_handle (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_UINT32:
+    case G_VARIANT_CLASS_UINT32:
       {
         guint64 value;
 
@@ -1531,7 +1531,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_uint32 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_INT64:
+    case G_VARIANT_CLASS_INT64:
       {
         gint64 value;
 
@@ -1543,7 +1543,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_int64 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_UINT64:
+    case G_VARIANT_CLASS_UINT64:
       {
         guint64 value;
 
@@ -1555,7 +1555,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_uint64 (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_DOUBLE:
       {
         gdouble floating;
 
@@ -1565,7 +1565,7 @@ terminal_get_value (AST                *ast,
         return g_variant_new_double (floating);
       }
 
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       {
         if (terminal->string == NULL)
           {
diff --git a/glib/gvariant-printer.c b/glib/gvariant-printer.c
index 90e5fbd..ad3cddf 100644
--- a/glib/gvariant-printer.c
+++ b/glib/gvariant-printer.c
@@ -74,9 +74,9 @@ g_variant_print_string (GVariant *value,
   if G_UNLIKELY (string == NULL)
       string = g_string_new (NULL);
 
-  switch (g_variant_get_type_class (value))
+  switch (g_variant_classify (value))
   {
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         GVariantIter iter;
 
@@ -110,7 +110,7 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariant *child = g_variant_get_variant (value);
 
@@ -125,7 +125,7 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
+    case G_VARIANT_CLASS_TUPLE:
       {
         GVariantIter iter;
 
@@ -146,7 +146,7 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         GVariantIter iter;
         GVariant *element;
@@ -173,14 +173,14 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BOOLEAN:
       if (g_variant_get_boolean (value))
         g_string_append (string, "true");
       else
         g_string_append (string, "false");
       break;
 
-    /*case G_VARIANT_TYPE_CLASS_MAYBE:
+    /*case G_VARIANT_CLASS_MAYBE:
       {
         if (g_variant_n_children (value))
           {
@@ -204,7 +204,7 @@ g_variant_print_string (GVariant *value,
         break;
       }*/
 
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       {
         const gchar *str = g_variant_get_string (value, NULL);
         gchar *escaped = g_strescape (str, NULL);
@@ -215,28 +215,28 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_BYTE:
+    case G_VARIANT_CLASS_BYTE:
       if (type_annotate)
         g_string_append (string, "byte ");
       g_string_append_printf (string, "0x%02x",
                               g_variant_get_byte (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT16:
+    case G_VARIANT_CLASS_INT16:
       if (type_annotate)
         g_string_append (string, "int16 ");
       g_string_append_printf (string, "%"G_GINT16_FORMAT,
                               g_variant_get_int16 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT16:
+    case G_VARIANT_CLASS_UINT16:
       if (type_annotate)
         g_string_append (string, "uint16 ");
       g_string_append_printf (string, "%"G_GUINT16_FORMAT,
                               g_variant_get_uint16 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT32:
+    case G_VARIANT_CLASS_INT32:
       /* Never annotate this type because it is the default for numbers
        * (and this is a *pretty* printer)
        */
@@ -244,35 +244,35 @@ g_variant_print_string (GVariant *value,
                               g_variant_get_int32 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_HANDLE:
+    case G_VARIANT_CLASS_HANDLE:
       if (type_annotate)
         g_string_append (string, "handle ");
       g_string_append_printf (string, "%"G_GINT32_FORMAT,
                               g_variant_get_handle (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT32:
+    case G_VARIANT_CLASS_UINT32:
       if (type_annotate)
         g_string_append (string, "uint32 ");
       g_string_append_printf (string, "%"G_GUINT32_FORMAT,
                               g_variant_get_uint32 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_INT64:
+    case G_VARIANT_CLASS_INT64:
       if (type_annotate)
         g_string_append (string, "int64 ");
       g_string_append_printf (string, "%"G_GINT64_FORMAT,
                               g_variant_get_int64 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT64:
+    case G_VARIANT_CLASS_UINT64:
       if (type_annotate)
         g_string_append (string, "uint64 ");
       g_string_append_printf (string, "%"G_GUINT64_FORMAT,
                               g_variant_get_uint64 (value));
       break;
 
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_DOUBLE:
       {
         gchar buffer[100];
         gint i;
@@ -296,14 +296,14 @@ g_variant_print_string (GVariant *value,
         break;
       }
 
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_OBJECT_PATH:
       if (type_annotate)
         g_string_append (string, "objectpath ");
       g_string_append_printf (string, "\"%s\"",
                               g_variant_get_string (value, NULL));
       break;
 
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_SIGNATURE:
       if (type_annotate)
         g_string_append (string, "signature");
       g_string_append_printf (string, "\"%s\"",
diff --git a/glib/gvariant-serialiser.c b/glib/gvariant-serialiser.c
index 037cfc8..e46dcfd 100644
--- a/glib/gvariant-serialiser.c
+++ b/glib/gvariant-serialiser.c
@@ -147,18 +147,18 @@ g_variant_serialised_n_children (GVariantSerialised container)
 {
   g_variant_serialised_assert_invariant (container);
 
-  switch (g_variant_type_info_get_type_class (container.type))
+  switch (g_variant_type_info_get_class (container.type))
   {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       return 1;
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
+    case G_VARIANT_CLASS_TUPLE:
       return g_variant_type_info_n_members (container.type);
 
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       return 2;
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         gsize size;
 
@@ -173,7 +173,7 @@ g_variant_serialised_n_children (GVariantSerialised container)
         return 1;
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         gsize fixed_size;
 
@@ -236,9 +236,9 @@ g_variant_serialised_get_child (GVariantSerialised container,
 {
   g_variant_serialised_assert_invariant (container);
 
-  switch (g_variant_type_info_get_type_class (container.type))
+  switch (g_variant_type_info_get_class (container.type))
   {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariantSerialised child = { NULL, container.data, container.size };
 
@@ -301,7 +301,7 @@ g_variant_serialised_get_child (GVariantSerialised container,
         return child;
       }
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         GVariantSerialised child;
         gsize fixed_size;
@@ -333,7 +333,7 @@ g_variant_serialised_get_child (GVariantSerialised container,
         return child;
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         GVariantSerialised child;
         gsize fixed_size;
@@ -402,8 +402,8 @@ g_variant_serialised_get_child (GVariantSerialised container,
         return child;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_TUPLE:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         const GVariantMemberInfo *info;
         GVariantSerialised child;
@@ -481,9 +481,9 @@ g_variant_serialiser_serialise (GVariantSerialised        container,
                                 const gpointer           *children,
                                 gsize                     n_children)
 {
-  switch (g_variant_type_info_get_type_class (container.type))
+  switch (g_variant_type_info_get_class (container.type))
   {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariantSerialised child = { NULL, container.data, 0 };
         const gchar *type_string;
@@ -511,7 +511,7 @@ g_variant_serialiser_serialise (GVariantSerialised        container,
         return;
       }
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         g_assert_cmpint (n_children, ==, (container.size > 0));
 
@@ -542,7 +542,7 @@ g_variant_serialiser_serialise (GVariantSerialised        container,
         return;
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         g_assert_cmpint ((n_children > 0), ==, (container.size > 0));
 
@@ -590,8 +590,8 @@ g_variant_serialiser_serialise (GVariantSerialised        container,
         return;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_TUPLE:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         if (n_children)
           {
@@ -673,9 +673,9 @@ g_variant_serialiser_needed_size (GVariantTypeInfo         *type,
                                   const gpointer           *children,
                                   gsize                     n_children)
 {
-  switch (g_variant_type_info_get_type_class (type))
+  switch (g_variant_type_info_get_class (type))
   {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariantSerialised child = {};
         const gchar *type_string;
@@ -688,7 +688,7 @@ g_variant_serialiser_needed_size (GVariantTypeInfo         *type,
         return child.size + 1 + strlen (type_string);
       }
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         GVariantSerialised child = { g_variant_type_info_element (type) };
         gsize fixed_size;
@@ -711,7 +711,7 @@ g_variant_serialiser_needed_size (GVariantTypeInfo         *type,
         return child.size;
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         GVariantTypeInfo *elem_type;
         gsize fixed_size;
@@ -750,8 +750,8 @@ g_variant_serialiser_needed_size (GVariantTypeInfo         *type,
           return fixed_size * n_children;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_TUPLE:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         gsize n_offsets;
         gsize offset;
@@ -910,26 +910,26 @@ g_variant_serialised_is_normal (GVariantSerialised value)
 {
 #define fail return FALSE
 //#define fail g_assert_not_reached ()
-  switch (g_variant_type_info_get_type_class (value.type))
+  switch (g_variant_type_info_get_class (value.type))
   {
-    case G_VARIANT_TYPE_CLASS_BYTE:
-    case G_VARIANT_TYPE_CLASS_INT16:
-    case G_VARIANT_TYPE_CLASS_UINT16:
-    case G_VARIANT_TYPE_CLASS_INT32:
-    case G_VARIANT_TYPE_CLASS_HANDLE:
-    case G_VARIANT_TYPE_CLASS_UINT32:
-    case G_VARIANT_TYPE_CLASS_INT64:
-    case G_VARIANT_TYPE_CLASS_UINT64:
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_BYTE:
+    case G_VARIANT_CLASS_INT16:
+    case G_VARIANT_CLASS_UINT16:
+    case G_VARIANT_CLASS_INT32:
+    case G_VARIANT_CLASS_HANDLE:
+    case G_VARIANT_CLASS_UINT32:
+    case G_VARIANT_CLASS_INT64:
+    case G_VARIANT_CLASS_UINT64:
+    case G_VARIANT_CLASS_DOUBLE:
       return TRUE;
 
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BOOLEAN:
       if (value.data[0] > 1)
         fail;
 
       return TRUE;
 
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       /* XXX this is not safe if the data changes... */
       if (value.size == 0 || value.data[value.size - 1] != '\0' ||
           strlen ((const char *) value.data) + 1 != value.size)
@@ -937,7 +937,7 @@ g_variant_serialised_is_normal (GVariantSerialised value)
 
       return TRUE;
 
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariantSerialised child = { NULL, value.data, value.size };
 
@@ -992,7 +992,7 @@ g_variant_serialised_is_normal (GVariantSerialised value)
         return g_variant_serialised_is_normal (child);
       }
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
       {
         gsize fixed_size;
 
@@ -1024,7 +1024,7 @@ g_variant_serialised_is_normal (GVariantSerialised value)
         return g_variant_serialised_is_normal (value);
       }
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
       {
         GVariantSerialised child = { g_variant_type_info_element (value.type),
                                      value.data,
@@ -1122,8 +1122,8 @@ g_variant_serialised_is_normal (GVariantSerialised value)
         return TRUE;
       }
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_TUPLE:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         const GVariantMemberInfo *info;
         guint offset_size;
@@ -1241,8 +1241,8 @@ g_variant_serialised_is_normal (GVariantSerialised value)
         return TRUE;
       }
 
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_OBJECT_PATH:
       return TRUE; /* XXX */
 
     default:
diff --git a/glib/gvariant-util.c b/glib/gvariant-util.c
index 6c71e7d..60959ec 100644
--- a/glib/gvariant-util.c
+++ b/glib/gvariant-util.c
@@ -768,16 +768,16 @@ const gchar *
 g_variant_get_string (GVariant *value,
                       gsize    *length)
 {
-  GVariantTypeClass class;
+  GVariantClass class;
   gboolean valid_string;
   const gchar *string;
   gssize size;
 
   g_return_val_if_fail (value != NULL, NULL);
-  class = g_variant_get_type_class (value);
-  g_return_val_if_fail (class == G_VARIANT_TYPE_CLASS_STRING ||
-                        class == G_VARIANT_TYPE_CLASS_OBJECT_PATH ||
-                        class == G_VARIANT_TYPE_CLASS_SIGNATURE, NULL);
+  class = g_variant_classify (value);
+  g_return_val_if_fail (class == G_VARIANT_CLASS_STRING ||
+                        class == G_VARIANT_CLASS_OBJECT_PATH ||
+                        class == G_VARIANT_CLASS_SIGNATURE, NULL);
 
   string = g_variant_get_data (value);
   size = g_variant_get_size (value);
@@ -794,7 +794,7 @@ g_variant_get_string (GVariant *value,
 
   switch (class)
   {
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       if (valid_string)
         break;
 
@@ -803,7 +803,7 @@ g_variant_get_string (GVariant *value,
 
       return "";
 
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_OBJECT_PATH:
       if (valid_string && g_variant_is_object_path (string))
         break;
 
@@ -812,7 +812,7 @@ g_variant_get_string (GVariant *value,
 
       return "/";
 
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_SIGNATURE:
       if (valid_string && g_variant_is_signature (string))
         break;
 
@@ -846,14 +846,14 @@ gchar *
 g_variant_dup_string (GVariant *value,
                       gsize    *length)
 {
-  GVariantTypeClass class;
+  GVariantClass class;
   int size;
 
   g_return_val_if_fail (value != NULL, NULL);
-  class = g_variant_get_type_class (value);
-  g_return_val_if_fail (class == G_VARIANT_TYPE_CLASS_STRING ||
-                        class == G_VARIANT_TYPE_CLASS_OBJECT_PATH ||
-                        class == G_VARIANT_TYPE_CLASS_SIGNATURE, NULL);
+  class = g_variant_classify (value);
+  g_return_val_if_fail (class == G_VARIANT_CLASS_STRING ||
+                        class == G_VARIANT_CLASS_OBJECT_PATH ||
+                        class == G_VARIANT_CLASS_SIGNATURE, NULL);
 
   size = g_variant_get_size (value);
 
@@ -890,7 +890,7 @@ struct _GVariantBuilder
 {
   GVariantBuilder *parent;
 
-  GVariantTypeClass class;
+  GVariantClass container_class;
   GVariantType *type;
   const GVariantType *expected;
   /* expected2 is always concrete.  it is set if adding a second
@@ -901,7 +901,7 @@ struct _GVariantBuilder
    *   sb = open(b, array, "ai");
    *   b = close (sb);
    *
-   *   b = open (b, array, "a*");    <-- valid
+   *   sb = open (b, array, "a*");   <-- valid
    *   add (sb, "u", 1234);          <-- must fail here
    *
    * the 'valid' call is valid since the "a*" is no more general than
@@ -911,6 +911,8 @@ struct _GVariantBuilder
    * separately.
    */
   const GVariantType *expected2;
+  gsize min_items;
+  gsize max_items;
 
   GVariant **children;
   gsize children_allocated;
@@ -961,18 +963,6 @@ g_variant_builder_resize (GVariantBuilder *builder,
   builder->children_allocated = new_allocated;
 }
 
-static gboolean
-g_variant_builder_check_add_value (GVariantBuilder  *builder,
-                                   GVariant         *value,
-                                   GError          **error)
-{
-  const GVariantType *type;
-
-  type = g_variant_get_type (value);
-
-  return g_variant_builder_check_add (builder, type, error);
-}
-
 /**
  * g_variant_builder_add_value:
  * @builder: a #GVariantBuilder
@@ -988,27 +978,24 @@ void
 g_variant_builder_add_value (GVariantBuilder *builder,
                              GVariant        *value)
 {
-  GError *error = NULL;
-
-  g_return_if_fail (builder != NULL);
-  g_return_if_fail (value != NULL);
-
-  if G_UNLIKELY (!g_variant_builder_check_add_value (builder, value, &error))
-    g_error ("g_variant_builder_add_value: %s", error->message);
+  g_return_if_fail (builder != NULL && value != NULL);
+  g_return_if_fail (g_variant_builder_check_add (builder,
+                                                 g_variant_get_type (value),
+                                                 NULL));
 
   builder->trusted &= g_variant_is_trusted (value);
 
-  if (builder->expected &&
-      (builder->class == G_VARIANT_TYPE_CLASS_TUPLE ||
-       builder->class == G_VARIANT_TYPE_CLASS_DICT_ENTRY))
-    builder->expected = g_variant_type_next (builder->expected);
+  if (builder->container_class == G_VARIANT_CLASS_TUPLE ||
+      builder->container_class == G_VARIANT_CLASS_DICT_ENTRY)
+    {
+      if (builder->expected)
+        builder->expected = g_variant_type_next (builder->expected);
 
-  if (builder->expected2 &&
-      (builder->class == G_VARIANT_TYPE_CLASS_TUPLE ||
-       builder->class == G_VARIANT_TYPE_CLASS_DICT_ENTRY))
-    builder->expected2 = g_variant_type_next (builder->expected2);
+      if (builder->expected2)
+        builder->expected2 = g_variant_type_next (builder->expected2);
+    }
 
-  if (builder->class == G_VARIANT_TYPE_CLASS_ARRAY &&
+  if (builder->container_class == G_VARIANT_CLASS_ARRAY &&
       builder->expected2 == NULL)
     builder->expected2 = g_variant_get_type (value);
 
@@ -1044,30 +1031,23 @@ GVariantBuilder *
 g_variant_builder_open (GVariantBuilder    *parent,
                         const GVariantType *type)
 {
-  GVariantTypeClass tclass;
   GVariantBuilder *child;
-  GError *error = NULL;
 
-  g_return_val_if_fail (parent != NULL, NULL);
-
-  tclass = g_variant_type_get_class (type);
-
-  if G_UNLIKELY (!g_variant_builder_check_add (parent, type, &error))
-    g_error ("g_variant_builder_open: %s", error->message);
-
-  if G_UNLIKELY (parent->has_child)
-    g_error ("GVariantBuilder already has open child");
+  g_return_val_if_fail (parent != NULL && type != NULL, NULL);
+  g_return_val_if_fail (g_variant_builder_check_add (parent, type, NULL),
+                        NULL);
+  g_return_val_if_fail (!parent->has_child, NULL);
 
   child = g_variant_builder_new (type);
 
   if (parent->expected2)
     {
-      if (tclass == G_VARIANT_TYPE_CLASS_MAYBE ||
-          tclass == G_VARIANT_TYPE_CLASS_ARRAY)
+      if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_MAYBE) ||
+          g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_ARRAY))
         child->expected2 = g_variant_type_element (parent->expected2);
       
-      if (tclass == G_VARIANT_TYPE_CLASS_TUPLE ||
-          tclass == G_VARIANT_TYPE_CLASS_DICT_ENTRY)
+      if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_TUPLE) ||
+          g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_DICT_ENTRY))
         child->expected2 = g_variant_type_first (parent->expected2);
 
       /* in variant case, we don't want to propagate the type */
@@ -1100,10 +1080,9 @@ g_variant_builder_close (GVariantBuilder *child)
   GVariant *value;
 
   g_return_val_if_fail (child != NULL, NULL);
-
-  g_assert (child->has_child == FALSE);
-  g_assert (child != NULL);
-  g_assert (child->parent != NULL);
+  g_return_val_if_fail (child->has_child == FALSE, NULL);
+  g_return_val_if_fail (child->parent != NULL, NULL);
+  g_assert (child->parent->has_child);
 
   parent = child->parent;
   parent->has_child = FALSE;
@@ -1118,7 +1097,7 @@ g_variant_builder_close (GVariantBuilder *child)
 
 /**
  * g_variant_builder_new:
- * @tclass: a container #GVariantTypeClass
+ * @tclass: a container #GVariantClass
  * @type: a type contained in @tclass, or %NULL
  * @returns: a #GVariantBuilder
  *
@@ -1127,9 +1106,9 @@ g_variant_builder_close (GVariantBuilder *child)
  * @tclass must be specified and must be a container type.
  *
  * If @type is given, it constrains the child values that it is
- * permissible to add.  If @tclass is not %G_VARIANT_TYPE_CLASS_VARIANT
+ * permissible to add.  If @tclass is not %G_VARIANT_CLASS_VARIANT
  * then @type must be contained in @tclass and will match the type of
- * the final value.  If @tclass is %G_VARIANT_TYPE_CLASS_VARIANT then
+ * the final value.  If @tclass is %G_VARIANT_CLASS_VARIANT then
  * @type must match the value that must be added to the variant.
  *
  * After the builder is created, values are added using
@@ -1141,65 +1120,72 @@ g_variant_builder_close (GVariantBuilder *child)
 GVariantBuilder *
 g_variant_builder_new (const GVariantType *type)
 {
-  GVariantTypeClass tclass;
   GVariantBuilder *builder;
 
-  g_assert (g_variant_type_is_container (type));
-  tclass = g_variant_type_get_class (type);
+  g_return_val_if_fail (type != NULL, NULL);
+  g_return_val_if_fail (g_variant_type_is_container (type), NULL);
 
   builder = g_slice_new (GVariantBuilder);
   builder->parent = NULL;
   builder->offset = 0;
   builder->has_child = FALSE;
-  builder->class = tclass;
-  builder->type = type ? g_variant_type_copy (type) : NULL;
+  builder->type = g_variant_type_copy (type);
   builder->expected = NULL;
   builder->trusted = TRUE;
-  builder->expected2 = FALSE;
+  builder->expected2 = NULL;
 
-  switch (tclass)
-  {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+  switch (*(const gchar *) type)
+    {
+    case G_VARIANT_CLASS_VARIANT:
+      builder->container_class = G_VARIANT_CLASS_VARIANT;
       builder->children_allocated = 1;
       builder->expected = NULL;
+      builder->min_items = 1;
+      builder->max_items = 1;
       break;
 
-    case G_VARIANT_TYPE_CLASS_ARRAY:
+    case G_VARIANT_CLASS_ARRAY:
+      builder->container_class = G_VARIANT_CLASS_ARRAY;
       builder->children_allocated = 8;
-      if (builder->type)
-        builder->expected = g_variant_type_element (builder->type);
+      builder->expected = g_variant_type_element (builder->type);
+      builder->min_items = 0;
+      builder->max_items = -1;
       break;
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
+    case G_VARIANT_CLASS_MAYBE:
+      builder->container_class = G_VARIANT_CLASS_MAYBE;
       builder->children_allocated = 1;
-      if (builder->type)
-        builder->expected = g_variant_type_element (builder->type);
+      builder->expected = g_variant_type_element (builder->type);
+      builder->min_items = 0;
+      builder->max_items = 1;
       break;
 
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_DICT_ENTRY:
+      builder->container_class = G_VARIANT_CLASS_DICT_ENTRY;
       builder->children_allocated = 2;
-      if (builder->type)
-        builder->expected = g_variant_type_key (builder->type);
+      builder->expected = g_variant_type_key (builder->type);
+      builder->min_items = 2;
+      builder->max_items = 2;
       break;
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
+    case 'r': /* G_VARIANT_TYPE_TUPLE was given */
+      builder->container_class = G_VARIANT_CLASS_TUPLE;
       builder->children_allocated = 8;
+      builder->expected = NULL;
+      builder->min_items = 0;
+      builder->max_items = -1;
+      break;
 
-      if (builder->type &&
-          g_variant_type_equal (builder->type, G_VARIANT_TYPE_ANY_TUPLE))
-        /* this is useless information.  they should have just said NULL */
-        {
-          g_variant_type_free (builder->type);
-          builder->type = NULL;
-        }
-
-      if (builder->type)
-        builder->expected = g_variant_type_first (builder->type);
-
+    case G_VARIANT_CLASS_TUPLE: /* a definite tuple type was given */
+      builder->container_class = G_VARIANT_CLASS_TUPLE;
+      builder->children_allocated = g_variant_type_n_items (type);
+      builder->expected = g_variant_type_first (builder->type);
+      builder->min_items = builder->children_allocated;
+      builder->max_items = builder->children_allocated;
       break;
 
     default:
-      g_error ("g_variant_builder_new() works only with container types");
+      g_assert_not_reached ();
    }
 
   builder->children = g_slice_alloc (sizeof (GVariant *) *
@@ -1225,76 +1211,74 @@ GVariant *
 g_variant_builder_end (GVariantBuilder *builder)
 {
   GVariantType *my_type;
-  GError *error = NULL;
   GVariant *value;
 
-  g_return_val_if_fail (builder, NULL);
+  g_return_val_if_fail (builder != NULL, NULL);
   g_return_val_if_fail (builder->parent == NULL, NULL);
-
-  if G_UNLIKELY (!g_variant_builder_check_end (builder, &error))
-    g_error ("g_variant_builder_end: %s", error->message);
+  g_return_val_if_fail (g_variant_builder_check_end (builder, NULL), NULL);
 
   g_variant_builder_resize (builder, builder->offset);
 
-  if (builder->class == G_VARIANT_TYPE_CLASS_VARIANT)
+  if (g_variant_type_is_concrete (builder->type))
     {
-      my_type = g_variant_type_copy (G_VARIANT_TYPE_VARIANT);
-      if (builder->type)
-        g_variant_type_free (builder->type);
-    }
-  else if (builder->type != NULL)
-    {
-      if (!g_variant_type_is_concrete (builder->type))
-        {
-          g_variant_type_free (builder->type);
-          builder->type = NULL;
-        }
-
-      my_type = builder->type;
+      my_type = g_variant_type_copy (builder->type);
     }
   else
-    my_type = NULL;
-
-
-  if (my_type == NULL)
-    switch (builder->class)
     {
-      case G_VARIANT_TYPE_CLASS_ARRAY:
-        my_type = g_variant_type_new_array (
-                    g_variant_get_type (builder->children[0]));
-        break;
-
-      case G_VARIANT_TYPE_CLASS_MAYBE:
-        my_type = g_variant_type_new_maybe (
-                    g_variant_get_type (builder->children[0]));
-        break;
-
-      case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
-        my_type = g_variant_type_new_dict_entry (
-                    g_variant_get_type (builder->children[0]),
-                    g_variant_get_type (builder->children[1]));
-        break;
-
-      case G_VARIANT_TYPE_CLASS_TUPLE:
+      switch (builder->container_class)
         {
-          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);
-        }
+        case G_VARIANT_CLASS_MAYBE:
+          {
+            const GVariantType *child_type;
+
+            child_type = g_variant_get_type (builder->children[0]);
+            my_type = g_variant_type_new_maybe (child_type);
+          }
+          break;
+
+        case G_VARIANT_CLASS_ARRAY:
+          {
+            const GVariantType *child_type;
+
+            child_type = g_variant_get_type (builder->children[0]);
+            my_type = g_variant_type_new_array (child_type);
+          }
+          break;
+
+        case G_VARIANT_CLASS_TUPLE:
+          {
+            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;
+
+        case G_VARIANT_CLASS_DICT_ENTRY:
+          {
+            const GVariantType *key_type, *value_type;
+
+            key_type = g_variant_get_type (builder->children[0]);
+            value_type = g_variant_get_type (builder->children[1]);
+            my_type = g_variant_type_new_dict_entry (key_type, value_type);
+          }
         break;
 
-      default:
-        g_assert_not_reached ();
+        case G_VARIANT_CLASS_VARIANT:
+          /* 'v' is surely a definite type, so this should never be hit */
+        default:
+          g_assert_not_reached ();
+        }
     }
 
   value = g_variant_new_tree (my_type, builder->children,
                               builder->offset, builder->trusted);
 
+  g_variant_type_free (builder->type);
   g_slice_free (GVariantBuilder, builder);
   g_variant_type_free (my_type);
 
@@ -1333,74 +1317,39 @@ g_variant_builder_check_end (GVariantBuilder  *builder,
   g_return_val_if_fail (builder != NULL, FALSE);
   g_return_val_if_fail (builder->has_child == FALSE, FALSE);
 
-  switch (builder->class)
-  {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
-      if (builder->offset < 1)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_FEW,
-                       "a variant must contain exactly one value");
-          return FALSE;
-        }
-      break;
-
-    case G_VARIANT_TYPE_CLASS_ARRAY:
-      if (builder->offset == 0 &&
-          (builder->type == NULL ||
-           !g_variant_type_is_concrete (builder->type)))
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_INFER,
-                       "unable to infer type for empty array");
-          return FALSE;
-        }
-      break;
-
-    case G_VARIANT_TYPE_CLASS_MAYBE:
-      if (builder->offset == 0 &&
-          (builder->type == NULL ||
-           !g_variant_type_is_concrete (builder->type)))
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_INFER,
-                       "unable to infer type for maybe with no value");
-          return FALSE;
-        }
-      break;
+  /* this function needs to check two things:
+   *
+   * 1) that we have the number of items required
+   * 2) in the case of an array or maybe type, either:
+   *      a) we have a definite type already
+   *      b) we have an item from which to infer the type
+   */
 
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
-      if (builder->offset < 2)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_FEW,
-                       "a dictionary entry must have a key and a value");
-          return FALSE;
-        }
-      break;
+  if (builder->offset < builder->min_items)
+    {
+      gchar *type_str;
 
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-      if (builder->expected)
-        {
-          gchar *type_string;
-
-          type_string = g_variant_type_dup_string (builder->type);
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_FEW,
-                       "a tuple of type %s must contain %" G_GSIZE_FORMAT
-                       " children but only %" G_GSIZE_FORMAT
-                       " have been given", type_string,
-                       g_variant_type_n_items (builder->type),
-                       builder->offset);
-          g_free (type_string);
+      type_str = g_variant_type_dup_string (builder->type);
+      g_set_error (error, G_VARIANT_BUILDER_ERROR,
+                   G_VARIANT_BUILDER_ERROR_TOO_FEW,
+                   "this container (type '%s') must contain %"G_GSIZE_FORMAT
+                   " values but only %"G_GSIZE_FORMAT "have been given",
+                   type_str, builder->min_items, builder->offset);
+      g_free (type_str);
 
-          return FALSE;
-        }
-      break;
+      return FALSE;
+    }
 
-    default:
-      g_assert_not_reached ();
-  }
+  if (!g_variant_type_is_concrete (builder->type) &&
+      (builder->container_class == G_VARIANT_CLASS_MAYBE ||
+       builder->container_class == G_VARIANT_CLASS_ARRAY) &&
+      builder->offset == 0)
+    {
+      g_set_error (error, G_VARIANT_BUILDER_ERROR,
+                   G_VARIANT_BUILDER_ERROR_INFER,
+                   "unable to infer type with no values present");
+      return FALSE;
+    }
 
   return TRUE;
 }
@@ -1408,7 +1357,7 @@ g_variant_builder_check_end (GVariantBuilder  *builder,
 /**
  * g_variant_builder_check_add:
  * @builder: a #GVariantBuilder
- * @tclass: a #GVariantTypeClass
+ * @tclass: a #GVariantClass
  * @type: a #GVariantType, or %NULL
  * @error: a #GError
  * @returns: %TRUE if adding is safe
@@ -1421,13 +1370,13 @@ g_variant_builder_check_end (GVariantBuilder  *builder,
  * g_variant_builder_close() has not yet been called).
  *
  * It is an error to call this function with an invalid @tclass
- * (including %G_VARIANT_TYPE_CLASS_INVALID) or a class that's not the
+ * (including %G_VARIANT_CLASS_INVALID) or a class that's not the
  * smallest class for some concrete type (for example,
- * %G_VARIANT_TYPE_CLASS_ALL).
+ * %G_VARIANT_CLASS_ALL).
  *
  * If @type is non-%NULL this function first checks that it is a
  * member of @tclass (except, as with g_variant_builder_new(), if
- * @tclass is %G_VARIANT_TYPE_CLASS_VARIANT then any @type is OK).
+ * @tclass is %G_VARIANT_CLASS_VARIANT then any @type is OK).
  *
  * The function then checks if any child of class @tclass (and type
  * @type, if given) would be suitable for adding to the builder.  If
@@ -1456,71 +1405,41 @@ g_variant_builder_check_add (GVariantBuilder     *builder,
                              const GVariantType  *type,
                              GError             **error)
 {
-  GVariantTypeClass tclass;
-
-  tclass = g_variant_type_get_class (type);
-
   g_return_val_if_fail (builder != NULL, FALSE);
+  g_return_val_if_fail (type != NULL, FALSE);
   g_return_val_if_fail (builder->has_child == FALSE, FALSE);
-  g_return_val_if_fail (tclass != G_VARIANT_TYPE_CLASS_INVALID &&
-                        tclass != G_VARIANT_TYPE_CLASS_ALL &&
-                        tclass != G_VARIANT_TYPE_CLASS_BASIC, FALSE);
-
-  if (tclass == G_VARIANT_TYPE_CLASS_VARIANT)
-    type = NULL;
 
-  /* basically, we need to check the following:
+  /* this function needs to check two things:
    *
-   * expected2 <= type <= tclass <= expected
+   * 1) that we have not exceeded the number of allowable items
+   * 2) that the incoming type matches the expected types like so:
    *
-   * but since any combination of the types may be %NULL, we need
-   * explicit checks:
+   *      expected2 <= type <= expected
+   *
+   * but since expected2 or expected could be %NULL, we need explicit checks:
    *
-   *   type <= class
-   *   tclass <= expected
    *   type <= expected
-   *   expected2 <= tclass
    *   expected2 <= type
    *
    * (we already know expected2 <= expected)
    */
 
-  /* type <= tclass */
-  if (type && g_variant_type_get_class (type) != tclass)
+  if (builder->offset == builder->max_items)
     {
       gchar *type_str;
 
-      type_str = g_variant_type_dup_string (type);
+      type_str = g_variant_type_dup_string (builder->type);
       g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                   G_VARIANT_BUILDER_ERROR_TYPE,
-                   "type '%s' is not in the correct class, expected '%c'",
-                   type_str, tclass);
+                   G_VARIANT_BUILDER_ERROR_TOO_MANY,
+                   "this container (type '%s') may not contain more than"
+                   " %"G_GSIZE_FORMAT " values", type_str, builder->offset);
       g_free (type_str);
-      return FALSE;
-    }
 
-  /* tclass <= expected */
-  if (builder->expected)
-    {
-      GVariantTypeClass expected_class;
-     
-      expected_class = g_variant_type_get_class (builder->expected);
-
-      if (expected_class != G_VARIANT_TYPE_CLASS_ALL &&
-          (expected_class != G_VARIANT_TYPE_CLASS_BASIC ||
-           !g_variant_type_class_is_basic (tclass)) &&
-          expected_class != tclass)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TYPE,
-                       "expecting value of class '%c', not '%c'",
-                       expected_class, tclass);
-          return FALSE;
-        }
+      return FALSE;
     }
 
   /* type <= expected */
-  if (builder->expected && type &&
+  if (builder->expected &&
       !g_variant_type_is_subtype_of (type, builder->expected))
     {
       gchar *expected_str, *type_str;
@@ -1536,10 +1455,9 @@ g_variant_builder_check_add (GVariantBuilder     *builder,
       return FALSE;
     }
 
-  /* expected2 <= tclass && expected2 <= type */
+  /* expected2 <= type */
   if (builder->expected2 &&
-      ((!g_variant_type_is_in_class (builder->expected2, tclass)) ||
-       (type && !g_variant_type_is_subtype_of (builder->expected2, type))))
+      !g_variant_type_is_subtype_of (builder->expected2, type))
     {
       g_set_error (error, G_VARIANT_BUILDER_ERROR,
                    G_VARIANT_BUILDER_ERROR_TYPE,
@@ -1547,72 +1465,6 @@ g_variant_builder_check_add (GVariantBuilder     *builder,
       return FALSE;
     }
 
-  switch (builder->class)
-  {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
-      if (builder->offset)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_MANY,
-                       "a variant cannot contain more than one value");
-          return FALSE;
-        }
-      break;
-
-    case G_VARIANT_TYPE_CLASS_ARRAY:
-      break;
-
-    case G_VARIANT_TYPE_CLASS_MAYBE:
-      if (builder->offset)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_MANY,
-                       "a maybe cannot contain more than one value");
-          return FALSE;
-        }
-      break;
-
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
-      if (builder->offset > 1)
-        {
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_MANY,
-                       "a dictionary entry may have only a key and a value");
-          return FALSE;
-        }
-      else if (builder->offset == 0)
-        {
-          if (!g_variant_type_class_is_basic (tclass))
-            {
-              g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                           G_VARIANT_BUILDER_ERROR_TYPE,
-                           "dictionary entry key must be a basic type");
-              return FALSE;
-            }
-        }
-      break;
-
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-      if (builder->type && builder->expected == NULL)
-        {
-          gchar *type_str;
-
-          type_str = g_variant_type_dup_string (builder->type);
-          g_set_error (error, G_VARIANT_BUILDER_ERROR,
-                       G_VARIANT_BUILDER_ERROR_TOO_MANY,
-                       "too many items (%" G_GSIZE_FORMAT 
-                       ") for this tuple type '%s'",
-                       builder->offset + 1, type_str);
-          g_free (type_str);
-
-          return FALSE;
-        }
-      break;
-
-    default:
-      g_assert_not_reached ();
-  }
-
   return TRUE;
 }
 
@@ -1697,22 +1549,6 @@ g_variant_get_type_string (GVariant *value)
 }
 
 /**
- * g_variant_get_type_class:
- * @value: a #GVariant
- * @returns: the #GVariantTypeClass of @value
- *
- * Returns the type class of @value.  This function is equivalent to
- * calling g_variant_get_type() followed by
- * g_variant_type_get_class().
- **/
-GVariantTypeClass
-g_variant_get_type_class (GVariant *value)
-{
-  g_return_val_if_fail (value != NULL, 0);
-  return g_variant_type_get_class (g_variant_get_type (value));
-}
-
-/**
  * g_variant_is_basic:
  * @value: a #GVariant
  * @returns: %TRUE if @value has a basic type
@@ -1726,7 +1562,8 @@ gboolean
 g_variant_is_basic (GVariant *value)
 {
   g_return_val_if_fail (value != NULL, FALSE);
-  return g_variant_type_class_is_basic (g_variant_get_type_class (value));
+  return g_variant_type_is_subtype_of (g_variant_get_type (value),
+                                       G_VARIANT_TYPE_ANY_BASIC);
 }
 
 /**
@@ -1744,7 +1581,7 @@ gboolean
 g_variant_is_container (GVariant *value)
 {
   g_return_val_if_fail (value != NULL, FALSE);
-  return g_variant_type_class_is_container (g_variant_get_type_class (value));
+  return !g_variant_is_basic (value);
 }
 
 #include <stdio.h>
@@ -1788,45 +1625,45 @@ g_variant_dump_data (GVariant *value)
 GVariant *
 g_variant_deep_copy (GVariant *value)
 {
-  switch (g_variant_get_type_class (value))
+  switch (g_variant_classify (value))
   {
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BOOLEAN:
       return g_variant_new_boolean (g_variant_get_boolean (value));
 
-    case G_VARIANT_TYPE_CLASS_BYTE:
+    case G_VARIANT_CLASS_BYTE:
       return g_variant_new_byte (g_variant_get_byte (value));
 
-    case G_VARIANT_TYPE_CLASS_INT16:
+    case G_VARIANT_CLASS_INT16:
       return g_variant_new_int16 (g_variant_get_int16 (value));
 
-    case G_VARIANT_TYPE_CLASS_UINT16:
+    case G_VARIANT_CLASS_UINT16:
       return g_variant_new_uint16 (g_variant_get_uint16 (value));
 
-    case G_VARIANT_TYPE_CLASS_INT32:
+    case G_VARIANT_CLASS_INT32:
       return g_variant_new_int32 (g_variant_get_int32 (value));
 
-    case G_VARIANT_TYPE_CLASS_UINT32:
+    case G_VARIANT_CLASS_UINT32:
       return g_variant_new_uint32 (g_variant_get_uint32 (value));
 
-    case G_VARIANT_TYPE_CLASS_INT64:
+    case G_VARIANT_CLASS_INT64:
       return g_variant_new_int64 (g_variant_get_int64 (value));
 
-    case G_VARIANT_TYPE_CLASS_UINT64:
+    case G_VARIANT_CLASS_UINT64:
       return g_variant_new_uint64 (g_variant_get_uint64 (value));
 
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_DOUBLE:
       return g_variant_new_double (g_variant_get_double (value));
       
-    case G_VARIANT_TYPE_CLASS_STRING:
+    case G_VARIANT_CLASS_STRING:
       return g_variant_new_string (g_variant_get_string (value, NULL));
 
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_OBJECT_PATH:
       return g_variant_new_object_path (g_variant_get_string (value, NULL));
 
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_SIGNATURE:
       return g_variant_new_signature (g_variant_get_string (value, NULL));
 
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       {
         GVariant *inside, *new;
        
@@ -1837,13 +1674,13 @@ g_variant_deep_copy (GVariant *value)
         return new;
       }
 
-    case G_VARIANT_TYPE_CLASS_HANDLE:
+    case G_VARIANT_CLASS_HANDLE:
       return g_variant_new_handle (g_variant_get_handle (value));
 
-    case G_VARIANT_TYPE_CLASS_MAYBE:
-    case G_VARIANT_TYPE_CLASS_ARRAY:
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+    case G_VARIANT_CLASS_MAYBE:
+    case G_VARIANT_CLASS_ARRAY:
+    case G_VARIANT_CLASS_TUPLE:
+    case G_VARIANT_CLASS_DICT_ENTRY:
       {
         GVariantBuilder *builder;
         GVariantIter iter;
diff --git a/glib/gvariant-valist.c b/glib/gvariant-valist.c
index 3e3b8d0..f9cea9b 100644
--- a/glib/gvariant-valist.c
+++ b/glib/gvariant-valist.c
@@ -396,8 +396,7 @@ g_variant_valist_new (const gchar **format_string,
                                                             NULL, NULL);
                   g_assert (g_variant_type_is_concrete (type));
 
-                  if (g_variant_type_is_in_class (type,
-                                                  G_VARIANT_TYPE_CLASS_ARRAY))
+                  if (g_variant_type_is_subtype_of (type, G_VARIANT_TYPE_ANY_ARRAY))
                     n_items = va_arg (*app, gsize);
                   else
                     n_items = 0;
diff --git a/glib/gvariant.h b/glib/gvariant.h
index c313aad..6b6398d 100644
--- a/glib/gvariant.h
+++ b/glib/gvariant.h
@@ -43,7 +43,6 @@ GVariant *                      g_variant_ref_sink                      (GVarian
 void                            g_variant_unref                         (GVariant             *value);
 void                            g_variant_flatten                       (GVariant             *value);
 
-GVariantTypeClass               g_variant_get_type_class                (GVariant             *value);
 const GVariantType *            g_variant_get_type                      (GVariant             *value);
 const gchar *                   g_variant_get_type_string               (GVariant             *value);
 gboolean                        g_variant_is_basic                      (GVariant             *value);
@@ -257,6 +256,8 @@ gsize                           g_variant_get_size                      (GVarian
 
 #define G_VARIANT_JUST ((gboolean *) "truetrue")
 
+GVariantClass                   g_variant_classify                      (GVariant            *value);
+
 G_END_DECLS
 
 #endif /* __G_VARIANT_H__ */
diff --git a/glib/gvarianttype.c b/glib/gvarianttype.c
index 650d72a..adf6d09 100644
--- a/glib/gvarianttype.c
+++ b/glib/gvarianttype.c
@@ -101,16 +101,6 @@
  * type string.
  **/
 
-#ifdef GVARIANT_DEBUG
-static gboolean
-g_variant_type_check (const GVariantType *type)
-{
-  const gchar *type_string = (const gchar *) type;
-
-  return g_variant_type_string_scan (type_string, NULL, &type_string);
-}
-#endif
-
 /**
  * g_variant_type_string_scan:
  * @string: a pointer to any string
@@ -431,6 +421,32 @@ g_variant_type_is_basic (const GVariantType *type)
   }
 }
 
+gboolean
+g_variant_type_is_maybe (const GVariantType *type)
+{
+  return g_variant_type_peek_string (type)[0] == 'm';
+}
+
+gboolean
+g_variant_type_is_array (const GVariantType *type)
+{
+  return g_variant_type_peek_string (type)[0] == 'a';
+}
+
+gboolean
+g_variant_type_is_tuple (const GVariantType *type)
+{
+  gchar type_char = g_variant_type_peek_string (type)[0];
+
+  return type_char == 'r' || type_char == '(';
+}
+
+gboolean
+g_variant_type_is_dict_entry (const GVariantType *type)
+{
+  return g_variant_type_peek_string (type)[0] == '{';
+}
+
 /**
  * g_variant_type_hash:
  * @type: a #GVariantType
@@ -541,8 +557,24 @@ g_variant_type_is_subtype_of (const GVariantType *type,
         {
           const GVariantType *target_type = (GVariantType *) type_string;
 
-          if (!g_variant_type_is_in_class (target_type, supertype_char))
-            return FALSE;
+          switch (supertype_char)
+            {
+            case 'r':
+              if (!g_variant_type_is_tuple (target_type))
+                return FALSE;
+              break;
+
+            case '*':
+              break;
+
+            case '?':
+              if (!g_variant_type_is_basic (target_type))
+                return FALSE;
+              break;
+
+            default:
+              return FALSE;
+            }
 
           type_string += g_variant_type_get_string_length (target_type);
         }
@@ -552,141 +584,6 @@ g_variant_type_is_subtype_of (const GVariantType *type,
 }
 
 /**
- * g_variant_type_is_in_class:
- * @type: a #GVariantType
- * @tclass: a #GVariantTypeClass
- * @returns: %TRUE if @type is in the given @class
- *
- * Determines if @type is contained within @class.
- *
- * Note that the class %G_VARIANT_TYPE_CLASS_ALL contains every type
- * and the class %G_VARIANT_TYPE_CLASS_BASIC contains every basic
- * type.
- **/
-gboolean
-g_variant_type_is_in_class (const GVariantType *type,
-                            GVariantTypeClass   tclass)
-{
-  char first_char = *(const gchar *) type;
-
-  switch (tclass)
-  {
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-      return first_char == '(' || first_char == 'r';
-
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
-      return first_char == '{';
-
-    case G_VARIANT_TYPE_CLASS_BASIC:
-      return g_variant_type_is_basic (type);
-
-    case G_VARIANT_TYPE_CLASS_ALL:
-      return TRUE;
-
-    default:
-      return tclass == first_char;
-  }
-}
-
-/**
- * g_variant_type_get_class:
- * @type: a #GVariantType
- * @returns: the smallest class containing @type
- *
- * Determines the smallest type class containing @type.
- *
- * For example, this function would return
- * %G_VARIANT_TYPE_CLASS_BOOLEAN for %G_VARIANT_TYPE_BOOLEAN and
- * %G_VARIANT_TYPE_CLASS_ARRAY for the type corresponding to the type
- * string "ai".  %G_VARIANT_TYPE_CLASS_ALL is returned for
- * %G_VARIANT_TYPE_ANY and for no other types (because although it
- * contains all types, it is not the smallest containing class for any
- * other type).
- **/
-GVariantTypeClass
-g_variant_type_get_class (const GVariantType *type)
-{
-  char first_char = *(const gchar *) type;
-
-  switch (first_char)
-  {
-    case '(':
-      return G_VARIANT_TYPE_CLASS_TUPLE;
-
-    case '{':
-      return G_VARIANT_TYPE_CLASS_DICT_ENTRY;
-
-    default:
-      return first_char;
-  }
-}
-
-/**
- * g_variant_type_class_is_container:
- * @tclass: a #GVariantTypeClass
- * @returns: %TRUE if @class is a container class
- *
- * Determines if @class is a container class.
- *
- * The following are considered to be container classes: maybe, array,
- * tuple, dict_entry and variant.
- **/
-gboolean
-g_variant_type_class_is_container (GVariantTypeClass tclass)
-{
-  switch (tclass)
-  {
-    case G_VARIANT_TYPE_CLASS_VARIANT:
-    case G_VARIANT_TYPE_CLASS_MAYBE:
-    case G_VARIANT_TYPE_CLASS_ARRAY:
-    case G_VARIANT_TYPE_CLASS_TUPLE:
-    case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
-      return TRUE;
-
-    default:
-      return FALSE;
-  }
-}
-
-/**
- * g_variant_type_class_is_basic:
- * @tclass: a #GVariantTypeClass
- * @returns: %TRUE if @class is a basic class
- *
- * Determines if @class is a basic class.
- *
- * The following are considered to be basic classes: boolean, byte,
- * the signed and unsigned integer classes, double, string, object
- * path and signature.  Additionally, the 'basic' type class is also
- * considered to be basic.
- **/
-gboolean
-g_variant_type_class_is_basic (GVariantTypeClass tclass)
-{
-  switch (tclass)
-  {
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
-    case G_VARIANT_TYPE_CLASS_BYTE:
-    case G_VARIANT_TYPE_CLASS_INT16:
-    case G_VARIANT_TYPE_CLASS_UINT16:
-    case G_VARIANT_TYPE_CLASS_INT32:
-    case G_VARIANT_TYPE_CLASS_HANDLE:
-    case G_VARIANT_TYPE_CLASS_UINT32:
-    case G_VARIANT_TYPE_CLASS_INT64:
-    case G_VARIANT_TYPE_CLASS_UINT64:
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
-    case G_VARIANT_TYPE_CLASS_STRING:
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
-    case G_VARIANT_TYPE_CLASS_BASIC:
-      return TRUE;
-
-    default:
-      return FALSE;
-  }
-}
-
-/**
  * g_variant_type_element:
  * @type: a #GVariantType of class array or maybe
  * @returns: the element type of @type
diff --git a/glib/gvarianttype.h b/glib/gvarianttype.h
index b40927d..62e41fe 100644
--- a/glib/gvarianttype.h
+++ b/glib/gvarianttype.h
@@ -21,78 +21,33 @@
 #ifndef __G_VARIANT_TYPE_H__
 #define __G_VARIANT_TYPE_H__
 
+#include <glib/gmessages.h>
 #include <glib/gtypes.h>
 
-typedef struct _GVariantType GVariantType;
-
-/**
- * GVariantTypeClass:
- * @G_VARIANT_TYPE_CLASS_INVALID: the class of no type
- * @G_VARIANT_TYPE_CLASS_BOOLEAN: the class containing the type %G_VARIANT_TYPE_BOOLEAN
- * @G_VARIANT_TYPE_CLASS_BYTE: the class containing the type %G_VARIANT_TYPE_BYTE
- * @G_VARIANT_TYPE_CLASS_INT16: the class containing the type %G_VARIANT_TYPE_INT16
- * @G_VARIANT_TYPE_CLASS_UINT16: the class containing the type %G_VARIANT_TYPE_UINT16
- * @G_VARIANT_TYPE_CLASS_INT32: the class containing the type %G_VARIANT_TYPE_INT32
- * @G_VARIANT_TYPE_CLASS_UINT32: the class containing the type %G_VARIANT_TYPE_UINT32
- * @G_VARIANT_TYPE_CLASS_INT64: the class containing the type %G_VARIANT_TYPE_INT64
- * @G_VARIANT_TYPE_CLASS_UINT64: the class containing the type %G_VARIANT_TYPE_UINT64
- * @G_VARIANT_TYPE_CLASS_DOUBLE: the class containing the type %G_VARIANT_TYPE_DOUBLE
- * @G_VARIANT_TYPE_CLASS_STRING: the class containing the type %G_VARIANT_TYPE_STRING
- * @G_VARIANT_TYPE_CLASS_OBJECT_PATH: the class containing the type %G_VARIANT_TYPE_OBJECT_PATH
- * @G_VARIANT_TYPE_CLASS_SIGNATURE: the class containing the type %G_VARIANT_TYPE_SIGNATURE
- * @G_VARIANT_TYPE_CLASS_VARIANT: the class containing the type %G_VARIANT_TYPE_VARIANT
- * @G_VARIANT_TYPE_CLASS_HANDLE: the class containing the type %G_VARIANT_TYPE_HANDLE
- * @G_VARIANT_TYPE_CLASS_MAYBE: the class containing all maybe types
- * @G_VARIANT_TYPE_CLASS_ARRAY: the class containing all array types
- * @G_VARIANT_TYPE_CLASS_TUPLE: the class containing all tuple types
- * @G_VARIANT_TYPE_CLASS_DICT_ENTRY: the class containing all dictionary entry types
- * @G_VARIANT_TYPE_CLASS_BASIC: the class containing all of the basic types (including %G_VARIANT_TYPE_ANY_BASIC and anything that matches it).
- * @G_VARIANT_TYPE_CLASS_ALL: the class containing all types (including %G_VARIANT_TYPE_ANY and anything that matches it).
- *
- * A enumerated type to group #GVariantType instances into classes.
- *
- * If you ever want to perform some sort of recursive operation on the
- * contents of a #GVariantType you will probably end up using a switch
- * statement over the #GVariantTypeClass of the type and its component
- * sub-types.
- *
- * A #GVariantType is said to "be in" a given #GVariantTypeClass.  The
- * type classes are overlapping, so a given #GVariantType may have
- * more than one type class.  For example, %G_VARIANT_TYPE_BOOLEAN is
- * of the following classes: %G_VARIANT_TYPE_CLASS_BOOLEAN,
- * %G_VARIANT_TYPE_CLASS_BASIC, %G_VARIANT_TYPE_CLASS_ALL.
- **/
 typedef enum
 {
-  G_VARIANT_TYPE_CLASS_INVALID           = '\0',
-  G_VARIANT_TYPE_CLASS_BOOLEAN            = 'b',
-  G_VARIANT_TYPE_CLASS_BYTE               = 'y',
-
-  G_VARIANT_TYPE_CLASS_INT16              = 'n',
-  G_VARIANT_TYPE_CLASS_UINT16             = 'q',
-  G_VARIANT_TYPE_CLASS_INT32              = 'i',
-  G_VARIANT_TYPE_CLASS_UINT32             = 'u',
-  G_VARIANT_TYPE_CLASS_INT64              = 'x',
-  G_VARIANT_TYPE_CLASS_UINT64             = 't',
+  G_VARIANT_CLASS_BOOLEAN       = 'b',
+  G_VARIANT_CLASS_BYTE          = 'y',
+  G_VARIANT_CLASS_INT16         = 'n',
+  G_VARIANT_CLASS_UINT16        = 'q',
+  G_VARIANT_CLASS_INT32         = 'i',
+  G_VARIANT_CLASS_UINT32        = 'u',
+  G_VARIANT_CLASS_INT64         = 'x',
+  G_VARIANT_CLASS_UINT64        = 't',
+  G_VARIANT_CLASS_HANDLE        = 'h',
+  G_VARIANT_CLASS_DOUBLE        = 'd',
+  G_VARIANT_CLASS_STRING        = 's',
+  G_VARIANT_CLASS_OBJECT_PATH   = 'o',
+  G_VARIANT_CLASS_SIGNATURE     = 'g',
+  G_VARIANT_CLASS_VARIANT       = 'v',
+  G_VARIANT_CLASS_MAYBE         = 'm',
+  G_VARIANT_CLASS_ARRAY         = 'a',
+  G_VARIANT_CLASS_TUPLE         = '(',
+  G_VARIANT_CLASS_DICT_ENTRY    = '{'
+} GVariantClass;
 
-  G_VARIANT_TYPE_CLASS_DOUBLE             = 'd',
 
-  G_VARIANT_TYPE_CLASS_STRING             = 's',
-  G_VARIANT_TYPE_CLASS_OBJECT_PATH        = 'o',
-  G_VARIANT_TYPE_CLASS_SIGNATURE          = 'g',
-
-  G_VARIANT_TYPE_CLASS_VARIANT            = 'v',
-
-  G_VARIANT_TYPE_CLASS_HANDLE             = 'h',
-
-  G_VARIANT_TYPE_CLASS_MAYBE              = 'm',
-  G_VARIANT_TYPE_CLASS_ARRAY              = 'a',
-  G_VARIANT_TYPE_CLASS_TUPLE              = 'r',
-  G_VARIANT_TYPE_CLASS_DICT_ENTRY         = 'e',
-
-  G_VARIANT_TYPE_CLASS_ALL                = '*',
-  G_VARIANT_TYPE_CLASS_BASIC              = '?'
-} GVariantTypeClass;
+typedef struct _GVariantType GVariantType;
 
 /**
  * G_VARIANT_TYPE_BOOLEAN:
@@ -293,6 +248,10 @@ gchar *                         g_variant_type_dup_string               (const G
 gboolean                        g_variant_type_is_concrete              (const GVariantType  *type);
 gboolean                        g_variant_type_is_container             (const GVariantType  *type);
 gboolean                        g_variant_type_is_basic                 (const GVariantType  *type);
+gboolean                        g_variant_type_is_maybe                 (const GVariantType  *type);
+gboolean                        g_variant_type_is_array                 (const GVariantType  *type);
+gboolean                        g_variant_type_is_tuple                 (const GVariantType  *type);
+gboolean                        g_variant_type_is_dict_entry            (const GVariantType  *type);
 
 /* for hash tables */
 guint                           g_variant_type_hash                     (gconstpointer        type);
@@ -303,13 +262,6 @@ gboolean                        g_variant_type_equal                    (gconstp
 gboolean                        g_variant_type_is_subtype_of            (const GVariantType  *type,
                                                                          const GVariantType  *supertype);
 
-/* class functions */
-gboolean                        g_variant_type_is_in_class              (const GVariantType  *type,
-                                                                         GVariantTypeClass    tclass);
-GVariantTypeClass               g_variant_type_get_class                (const GVariantType  *type);
-gboolean                        g_variant_type_class_is_container       (GVariantTypeClass    tclass);
-gboolean                        g_variant_type_class_is_basic           (GVariantTypeClass    tclass);
-
 /* type iterator interface */
 const GVariantType *            g_variant_type_element                  (const GVariantType  *type);
 const GVariantType *            g_variant_type_first                    (const GVariantType  *type);
@@ -326,12 +278,18 @@ GVariantType *                  g_variant_type_new_tuple                (const G
 GVariantType *                  g_variant_type_new_dict_entry           (const GVariantType  *key,
                                                                          const GVariantType  *value);
 
-/*< private >*/
-const GVariantType *            g_variant_type_check_string_            (const gchar         *type_string);
+#ifdef G_CAN_INLINE
+static inline const GVariantType *
+_g_variant_type (const gchar *type_string)
+{
+  g_return_val_if_fail (g_variant_type_string_is_valid (type_string), NULL);
+  return (const GVariantType *) type_string;
+}
+#define G_VARIANT_TYPE(type_string) _g_variant_type((type_string))
+#else
+#define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string))
+#endif
 
 G_END_DECLS
 
-#define G_VARIANT_TYPE(type_string) \
-  (g_variant_type_check_string_ (type_string))
-
 #endif /* __G_VARIANT_TYPE_H__ */
diff --git a/glib/gvarianttypeinfo.c b/glib/gvarianttypeinfo.c
index c896d32..9b8592d 100644
--- a/glib/gvarianttypeinfo.c
+++ b/glib/gvarianttypeinfo.c
@@ -65,12 +65,12 @@ g_variant_type_info_get_string (GVariantTypeInfo *info)
   return (const gchar *) info->type;
 }
 
-GVariantTypeClass
-g_variant_type_info_get_type_class (GVariantTypeInfo *info)
+GVariantClass
+g_variant_type_info_get_class (GVariantTypeInfo *info)
 {
   g_assert_cmpint (info->ref_count, >, 0);
 
-  return g_variant_type_get_class (info->type);
+  return *info->str;
 }
 
 void
@@ -311,7 +311,7 @@ g_variant_type_info_member_info (GVariantTypeInfo *info,
 /* == base == */
 #define BASE_INFO_CLASS '\0'
 static GVariantTypeInfo *
-base_info_new (const GVariantTypeClass class)
+base_info_new (const GVariantClass class)
 {
   GVariantTypeInfo *info;
 
@@ -320,40 +320,40 @@ base_info_new (const GVariantTypeClass class)
 
   switch (class)
   {
-    case G_VARIANT_TYPE_CLASS_BOOLEAN:
-    case G_VARIANT_TYPE_CLASS_BYTE:
+    case G_VARIANT_CLASS_BOOLEAN:
+    case G_VARIANT_CLASS_BYTE:
       info->alignment = 1 - 1;
       info->fixed_size = 1;
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT16:
-    case G_VARIANT_TYPE_CLASS_INT16:
+    case G_VARIANT_CLASS_UINT16:
+    case G_VARIANT_CLASS_INT16:
       info->alignment = 2 - 1;
       info->fixed_size = 2;
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT32:
-    case G_VARIANT_TYPE_CLASS_INT32:
-    case G_VARIANT_TYPE_CLASS_HANDLE:
+    case G_VARIANT_CLASS_UINT32:
+    case G_VARIANT_CLASS_INT32:
+    case G_VARIANT_CLASS_HANDLE:
       info->alignment = 4 - 1;
       info->fixed_size = 4;
       break;
 
-    case G_VARIANT_TYPE_CLASS_UINT64:
-    case G_VARIANT_TYPE_CLASS_INT64:
-    case G_VARIANT_TYPE_CLASS_DOUBLE:
+    case G_VARIANT_CLASS_UINT64:
+    case G_VARIANT_CLASS_INT64:
+    case G_VARIANT_CLASS_DOUBLE:
       info->alignment = 8 - 1;
       info->fixed_size = 8;
       break;
 
-    case G_VARIANT_TYPE_CLASS_VARIANT:
+    case G_VARIANT_CLASS_VARIANT:
       info->alignment = 8 - 1;
       info->fixed_size = 0;
       break;
 
-    case G_VARIANT_TYPE_CLASS_STRING:
-    case G_VARIANT_TYPE_CLASS_OBJECT_PATH:
-    case G_VARIANT_TYPE_CLASS_SIGNATURE:
+    case G_VARIANT_CLASS_STRING:
+    case G_VARIANT_CLASS_OBJECT_PATH:
+    case G_VARIANT_CLASS_SIGNATURE:
       info->alignment = 1 - 1;
       info->fixed_size = 0;
       break;
@@ -389,19 +389,19 @@ g_variant_type_info_get (const GVariantType *type)
 
   if (info == NULL)
     {
-      GVariantTypeClass class;
+      GVariantClass class;
 
-      class = g_variant_type_get_class (type);
+      class = *(const gchar *) type;
 
       switch (class)
       {
-        case G_VARIANT_TYPE_CLASS_MAYBE:
-        case G_VARIANT_TYPE_CLASS_ARRAY:
+        case G_VARIANT_CLASS_MAYBE:
+        case G_VARIANT_CLASS_ARRAY:
           info = array_info_new (type);
           break;
 
-        case G_VARIANT_TYPE_CLASS_TUPLE:
-        case G_VARIANT_TYPE_CLASS_DICT_ENTRY:
+        case G_VARIANT_CLASS_TUPLE:
+        case G_VARIANT_CLASS_DICT_ENTRY:
           info = tuple_info_new (type);
           break;
 
diff --git a/glib/gvarianttypeinfo.h b/glib/gvarianttypeinfo.h
index 643b178..ae5e05a 100644
--- a/glib/gvarianttypeinfo.h
+++ b/glib/gvarianttypeinfo.h
@@ -37,7 +37,7 @@ typedef struct
 
 /* query */
 const GVariantType *            g_variant_type_info_get_type            (GVariantTypeInfo   *typeinfo);
-GVariantTypeClass               g_variant_type_info_get_type_class      (GVariantTypeInfo   *typeinfo);
+GVariantClass                   g_variant_type_info_get_class           (GVariantTypeInfo   *typeinfo);
 const gchar *                   g_variant_type_info_get_string          (GVariantTypeInfo   *typeinfo);
 
 void                            g_variant_type_info_query               (GVariantTypeInfo   *typeinfo,
diff --git a/glib/tests/gvariant-big.c b/glib/tests/gvariant-big.c
index 54ea802..d1714ed 100644
--- a/glib/tests/gvariant-big.c
+++ b/glib/tests/gvariant-big.c
@@ -48,13 +48,13 @@ verify2 (GVariant *value,
   gsize length = g_rand_int_range (rand, 1, 1000);
   const gchar *possible = "ybquds";
   const GVariantType *type;
-  GVariantTypeClass class;
+  GVariantClass class;
   GVariantIter iter;
   GVariant *child;
   gsize actual;
 
   type = (const GVariantType *) (possible + g_rand_int_range (rand, 0, 6));
-  class = g_variant_type_get_class (type);
+  class = *(const gchar *) type;
 
   actual = g_variant_iter_init (&iter, value);
   g_assert_cmpint (actual, ==, length);
@@ -64,32 +64,32 @@ verify2 (GVariant *value,
     {
       switch (class)
         {
-          case G_VARIANT_TYPE_CLASS_BOOLEAN:
+          case G_VARIANT_CLASS_BOOLEAN:
             g_assert_cmpint (g_variant_get_boolean (child), ==,
                              g_rand_int_range (rand, 0, 1));
             break;
 
-          case G_VARIANT_TYPE_CLASS_BYTE:
+          case G_VARIANT_CLASS_BYTE:
             g_assert_cmpint (g_variant_get_byte (child), ==,
                              g_rand_int_range (rand, 0, 256));
             break;
 
-          case G_VARIANT_TYPE_CLASS_UINT16:
+          case G_VARIANT_CLASS_UINT16:
             g_assert_cmpint (g_variant_get_uint16 (child), ==,
                              g_rand_int_range (rand, 0, 65536));
             break;
 
-          case G_VARIANT_TYPE_CLASS_UINT32:
+          case G_VARIANT_CLASS_UINT32:
             g_assert_cmpint (g_variant_get_uint32 (child), ==,
                              g_rand_int (rand));
             break;
 
-          case G_VARIANT_TYPE_CLASS_DOUBLE:
+          case G_VARIANT_CLASS_DOUBLE:
             g_assert_cmpfloat (g_variant_get_double (child), ==,
                                ieee754ify (g_rand_double (rand)));
             break;
 
-          case G_VARIANT_TYPE_CLASS_STRING:
+          case G_VARIANT_CLASS_STRING:
             g_assert_cmpstr (g_variant_get_string (child, NULL), ==,
                              random_string (rand));
             break;
@@ -111,42 +111,42 @@ generate2 (GRand *rand)
   gsize length = g_rand_int_range (rand, 1, 1000);
   const gchar *possible = "ybquds";
   const GVariantType *type;
-  GVariantTypeClass class;
+  GVariantClass class;
   GVariantBuilder *builder;
   gsize i;
 
   type = (const GVariantType *) (possible + g_rand_int_range (rand, 0, 6));
-  class = g_variant_type_get_class (type);
+  class = *(const gchar *) type;
 
   builder = g_variant_builder_new (G_VARIANT_TYPE_ANY_ARRAY);
   for (i = 0; i < length; i++)
     {
       switch (class)
         {
-          case G_VARIANT_TYPE_CLASS_BOOLEAN:
+          case G_VARIANT_CLASS_BOOLEAN:
             g_variant_builder_add (builder, "b",
                                    g_rand_int_range (rand, 0, 1));
             break;
 
-          case G_VARIANT_TYPE_CLASS_BYTE:
+          case G_VARIANT_CLASS_BYTE:
             g_variant_builder_add (builder, "y",
                                    g_rand_int_range (rand, 0, 256));
             break;
 
-          case G_VARIANT_TYPE_CLASS_UINT16:
+          case G_VARIANT_CLASS_UINT16:
             g_variant_builder_add (builder, "q",
                                    g_rand_int_range (rand, 0, 65536));
             break;
 
-          case G_VARIANT_TYPE_CLASS_UINT32:
+          case G_VARIANT_CLASS_UINT32:
             g_variant_builder_add (builder, "u", g_rand_int (rand));
             break;
 
-          case G_VARIANT_TYPE_CLASS_DOUBLE:
+          case G_VARIANT_CLASS_DOUBLE:
             g_variant_builder_add (builder, "d", g_rand_double (rand));
             break;
 
-          case G_VARIANT_TYPE_CLASS_STRING:
+          case G_VARIANT_CLASS_STRING:
             g_variant_builder_add (builder, "s", random_string (rand));
             break;
             



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