[glib/gvariant-core] Some small fixups



commit c43e69b0613c30f9b3b2995d4dcfee76e0ca3a0c
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Feb 10 01:35:54 2010 -0500

    Some small fixups

 glib/gvariant-core.c |   30 +++++++++++++++++++++++++-----
 gobject/gboxed.h     |    1 +
 2 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/glib/gvariant-core.c b/glib/gvariant-core.c
index c3674d4..19518c0 100644
--- a/glib/gvariant-core.c
+++ b/glib/gvariant-core.c
@@ -102,6 +102,9 @@ struct _GVariant
  *            type of the instance.  When the instance is freed, this
  *            reference must be released with g_variant_type_info_unref().
  *
+ *            The type_info field never changes during the life of the
+ *            instance, so it can be accessed without a lock.
+ *
  * size: this is the size of the serialised form for the instance, if it
  *       is known.  If the instance is in serialised form then it is, by
  *       definition, known.  If the instance is in tree form then it may
@@ -113,12 +116,22 @@ struct _GVariant
  *       determined so that a large enough buffer can be allocated for
  *       the data.
  *
+ *       Once the size is known, it can never become unknown again.
+ *       g_variant_ensure_size() is used to ensure that the size is in
+ *       the known state -- it calculates the size if needed.  After
+ *       that, the size field can be accessed without a lock.
+ *
  * contents: a union containing either the information associated with
  *           holding a value in serialised form or holding a value in
  *           tree form.
  *
  *   .serialised: Only valid when the instance is in serialised form.
  *
+ *                Since an instance can never transition away from
+ *                serialised form, once these fields are set, they will
+ *                never be changed.  It is therefore valid to access
+ *                them without holding a lock.
+ *
  *     .buffer: the #GBuffer that contains the memory pointed to by
  *              .data, or %NULL if .data is %NULL.  In the event that
  *              the instance was deserialised from another instance,
@@ -142,8 +155,8 @@ struct _GVariant
  *                size, but this pointer will be %NULL.  This is exactly
  *                the reason that g_variant_get_data() sometimes returns
  *                %NULL.  For all other calls, the effect should be as
- *                if .data pointed to the appropriate number of
- *                zero-filled bytes.
+ *                if .data pointed to the appropriate number of nul
+ *                bytes.
  *
  *   .tree: Only valid when the instance is in tree form.
  *
@@ -220,7 +233,7 @@ g_variant_unlock (GVariant *value)
 }
 
 /* < private >
- * g_variant_release_childn:
+ * g_variant_release_children:
  * @value: a #GVariant
  *
  * Releases the reference held on each child in the 'children' array of
@@ -395,6 +408,9 @@ g_variant_fill_gvs (GVariantSerialised *serialised,
   g_assert (serialised->size == value->size);
 
   if (serialised->data)
+    /* g_variant_store() is a public API, so it
+     * it will reacquire the lock if it needs to.
+     */
     g_variant_store (value, serialised->data);
 }
 
@@ -575,6 +591,10 @@ g_variant_unref (GVariant *value)
 {
   if (g_atomic_int_dec_and_test (&value->ref_count))
     {
+      if G_UNLIKELY (value->state & STATE_LOCKED)
+        g_critical ("attempting to free a locked GVariant instance.  "
+                    "This should never happen.");
+
       g_variant_type_info_unref (value->type_info);
 
       if (value->state & STATE_SERIALISED)
@@ -685,8 +705,8 @@ g_variant_get_size (GVariant *value)
  * If @value is a fixed-sized value that was deserialised from a
  * corrupted serialised container then %NULL may be returned.  In this
  * case, the proper thing to do is typically to use the appropriate
- * number of zero-filled bytes in place of @value.  If @value is not
- * fixed-sized then %NULL is never returned.
+ * number of nul bytes in place of @value.  If @value is not fixed-sized
+ * then %NULL is never returned.
  *
  * In the case that @value is already in serialised form, this function
  * is O(1).  If the value is not already in serialised form,
diff --git a/gobject/gboxed.h b/gobject/gboxed.h
index 11daba5..10e293f 100644
--- a/gobject/gboxed.h
+++ b/gobject/gboxed.h
@@ -220,6 +220,7 @@ GType   g_hash_table_get_type   (void)  G_GNUC_CONST;
 GType   g_array_get_type        (void)  G_GNUC_CONST;
 GType   g_byte_array_get_type   (void)  G_GNUC_CONST;
 GType   g_ptr_array_get_type    (void)  G_GNUC_CONST;
+GType   g_variant_type_get_gtype(void)  G_GNUC_CONST;
 GType   g_variant_get_gtype     (void)  G_GNUC_CONST;
 GType   g_regex_get_type        (void)  G_GNUC_CONST;
 



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