=== Released 2.2.0 ===
[platform/upstream/glib.git] / gobject / gobject.c
index f9ade44..308c440 100644 (file)
  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  * Boston, MA 02111-1307, USA.
  */
+#include       "gobject.h"
 
 /*
  * MT safe
  */
 
-#include       "gobject.h"
-
-
 #include       "gvaluecollector.h"
 #include       "gsignal.h"
 #include       "gparamspecs.h"
 #include       "gvaluetypes.h"
+#include       "gobjectnotifyqueue.c"
 #include       <string.h>
+#include       <signal.h>
 
 
 #define        PREALLOC_CPARAMS        (8)
 
 
 /* --- macros --- */
-#define PARAM_SPEC_PARAM_ID(pspec)     (GPOINTER_TO_UINT (g_param_spec_get_qdata ((pspec), quark_property_id)))
+#define PARAM_SPEC_PARAM_ID(pspec)             ((pspec)->param_id)
+#define        PARAM_SPEC_SET_PARAM_ID(pspec, id)      ((pspec)->param_id = (id))
 
 
 /* --- signals --- */
 enum {
-  PROPERTIES_CHANGED,
   NOTIFY,
   LAST_SIGNAL
 };
@@ -52,10 +52,6 @@ enum {
 };
 
 
-/* --- typedefs --- */
-typedef struct _NotifyQueue NotifyQueue;
-
-
 /* --- prototypes --- */
 static void    g_object_base_class_init                (GObjectClass   *class);
 static void    g_object_base_class_finalize            (GObjectClass   *class);
@@ -65,7 +61,7 @@ static GObject*       g_object_constructor                    (GType                  type,
                                                         guint                  n_construct_properties,
                                                         GObjectConstructParam *construct_params);
 static void    g_object_last_unref                     (GObject        *object);
-static void    g_object_shutdown                       (GObject        *object);
+static void    g_object_real_dispose                   (GObject        *object);
 static void    g_object_finalize                       (GObject        *object);
 static void    g_object_do_set_property                (GObject        *object,
                                                         guint           property_id,
@@ -93,41 +89,21 @@ static gchar*       g_value_object_lcopy_value              (const GValue   *value,
 static void    g_object_dispatch_properties_changed    (GObject        *object,
                                                         guint           n_pspecs,
                                                         GParamSpec    **pspecs);
-static void    g_object_properties_changed             (GObject        *object,
-                                                        guint           n_pspecs,
-                                                        GParamSpec    **pspecs);
-static void    g_object_notify_property_changed        (GObject        *object,
-                                                        GParamSpec     *pspec);
-static inline NotifyQueue* object_freeze_notifies      (GObject        *object);
-static inline void        object_queue_property        (GObject        *object,
-                                                        GParamSpec     *pspec,
-                                                        NotifyQueue    *nqueue);
-static inline void        object_thaw_notifies         (GObject        *object,
-                                                        NotifyQueue    *nqueue);
 static inline void         object_get_property         (GObject        *object,
                                                         GParamSpec     *pspec,
                                                         GValue         *value);
 static inline void        object_set_property          (GObject        *object,
                                                         GParamSpec     *pspec,
                                                         const GValue   *value,
-                                                        NotifyQueue    *nqueue);
-
-
-/* --- structures --- */
-struct _NotifyQueue
-{
-  GSList *pspecs;
-  guint   n_pspecs;
-  guint   freeze_count;
-};
+                                                        GObjectNotifyQueue *nqueue);
 
 
 /* --- variables --- */
-static GQuark           quark_notify_queue = 0;
-static GQuark           quark_property_id = 0;
-static GQuark           quark_closure_array = 0;
-static GParamSpecPool   *pspec_pool = NULL;
-static gulong           gobject_signals[LAST_SIGNAL] = { 0, };
+static GQuark              quark_closure_array = 0;
+static GQuark              quark_weak_refs = 0;
+static GParamSpecPool      *pspec_pool = NULL;
+static GObjectNotifyContext property_notify_context = { 0, };
+static gulong              gobject_signals[LAST_SIGNAL] = { 0, };
 
 
 /* --- functions --- */
@@ -155,11 +131,8 @@ debug_objects_atexit (void)
   IF_DEBUG (OBJECTS)
     {
       G_LOCK (debug_objects);
-      if (debug_objects_ht)
-       {
-         g_message ("stale GObjects: %u", debug_objects_count);
-         g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
-       }
+      g_message ("stale GObjects: %u", debug_objects_count);
+      g_hash_table_foreach (debug_objects_ht, debug_objects_foreach, NULL);
       G_UNLOCK (debug_objects);
     }
 }
@@ -208,7 +181,10 @@ g_object_type_init (void)  /* sync with gtype.c */
   
 #ifdef G_ENABLE_DEBUG
   IF_DEBUG (OBJECTS)
-    g_atexit (debug_objects_atexit);
+    {
+      debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
+      g_atexit (debug_objects_atexit);
+    }
 #endif /* G_ENABLE_DEBUG */
 }
 
@@ -218,8 +194,6 @@ g_object_base_class_init (GObjectClass *class)
   GObjectClass *pclass = g_type_class_peek_parent (class);
 
   /* reset instance specific fields and methods that don't get inherited */
-  class->n_property_specs = 0;
-  class->property_specs = NULL;
   class->construct_properties = pclass ? g_slist_copy (pclass->construct_properties) : NULL;
   class->get_property = NULL;
   class->set_property = NULL;
@@ -228,71 +202,75 @@ g_object_base_class_init (GObjectClass *class)
 static void
 g_object_base_class_finalize (GObjectClass *class)
 {
-  guint i;
+  GList *list, *node;
   
-  g_message ("finallizing base class of %s", G_OBJECT_CLASS_NAME (class));
-
   _g_signals_destroy (G_OBJECT_CLASS_TYPE (class));
 
   g_slist_free (class->construct_properties);
   class->construct_properties = NULL;
-  for (i = 0; i < class->n_property_specs; i++)
+  list = g_param_spec_pool_list_owned (pspec_pool, G_OBJECT_CLASS_TYPE (class));
+  for (node = list; node; node = node->next)
     {
-      GParamSpec *pspec = class->property_specs[i];
+      GParamSpec *pspec = node->data;
       
       g_param_spec_pool_remove (pspec_pool, pspec);
-      g_param_spec_set_qdata (pspec, quark_property_id, NULL);
+      PARAM_SPEC_SET_PARAM_ID (pspec, 0);
       g_param_spec_unref (pspec);
     }
-  class->n_property_specs = 0;
-  g_free (class->property_specs);
-  class->property_specs = NULL;
+  g_list_free (list);
+}
+
+static void
+g_object_notify_dispatcher (GObject     *object,
+                           guint        n_pspecs,
+                           GParamSpec **pspecs)
+{
+  G_OBJECT_GET_CLASS (object)->dispatch_properties_changed (object, n_pspecs, pspecs);
 }
 
 static void
 g_object_do_class_init (GObjectClass *class)
 {
-  quark_notify_queue = g_quark_from_static_string ("GObject-notify-queue");
-  quark_property_id = g_quark_from_static_string ("GObject-property-id");
+  /* read the comment about typedef struct CArray; on why not to change this quark */
   quark_closure_array = g_quark_from_static_string ("GObject-closure-array");
+
+  quark_weak_refs = g_quark_from_static_string ("GObject-weak-references");
   pspec_pool = g_param_spec_pool_new (TRUE);
+  property_notify_context.quark_notify_queue = g_quark_from_static_string ("GObject-notify-queue");
+  property_notify_context.dispatcher = g_object_notify_dispatcher;
   
   class->constructor = g_object_constructor;
   class->set_property = g_object_do_set_property;
   class->get_property = g_object_do_get_property;
-  class->shutdown = g_object_shutdown;
+  class->dispose = g_object_real_dispose;
   class->finalize = g_object_finalize;
   class->dispatch_properties_changed = g_object_dispatch_properties_changed;
-  class->properties_changed = g_object_properties_changed;
-  class->notify = g_object_notify_property_changed;
-
-  gobject_signals[PROPERTIES_CHANGED] =
-    g_signal_newc ("properties_changed",
-                   G_TYPE_FROM_CLASS (class),
-                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
-                   G_STRUCT_OFFSET (GObjectClass, properties_changed),
-                   NULL, NULL,
-                  g_cclosure_marshal_VOID__UINT_POINTER,
-                   G_TYPE_NONE,
-                   2, G_TYPE_UINT, G_TYPE_POINTER);
-  gobject_signals[NOTIFY] =
-    g_signal_newc ("notify",
-                   G_TYPE_FROM_CLASS (class),
-                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
-                   G_STRUCT_OFFSET (GObjectClass, notify),
-                  NULL, NULL,
-                   g_cclosure_marshal_VOID__PARAM,
-                   G_TYPE_NONE,
-                   1, G_TYPE_PARAM);
-}
+  class->notify = NULL;
 
+  gobject_signals[NOTIFY] =
+    g_signal_new ("notify",
+                 G_TYPE_FROM_CLASS (class),
+                 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
+                 G_STRUCT_OFFSET (GObjectClass, notify),
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__PARAM,
+                 G_TYPE_NONE,
+                 1, G_TYPE_PARAM);
+}
+
+/**
+ * g_object_class_install_property:
+ * @class: a #GObjectClass
+ * @property_id: the id for the new property
+ * @pspec: the #GParamSpec for the new property
+ * 
+ * Installs a new property. This is usually done in the class initializer.
+ **/
 void
 g_object_class_install_property (GObjectClass *class,
                                 guint         property_id,
                                 GParamSpec   *pspec)
 {
-  guint i;
-  
   g_return_if_fail (G_IS_OBJECT_CLASS (class));
   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
   if (pspec->flags & G_PARAM_WRITABLE)
@@ -306,18 +284,6 @@ g_object_class_install_property (GObjectClass *class,
   if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
     g_return_if_fail (pspec->flags & G_PARAM_WRITABLE);
 
-  /* expensive paranoia checks ;( */
-  for (i = 0; i < class->n_property_specs; i++)
-    if (PARAM_SPEC_PARAM_ID (class->property_specs[i]) == property_id)
-      {
-       g_warning (G_STRLOC ": class `%s' already contains a property `%s' with id %u, "
-                  "cannot install property `%s'",
-                  G_OBJECT_CLASS_NAME (class),
-                  class->property_specs[i]->name,
-                  property_id,
-                  pspec->name);
-       return;
-      }
   if (g_param_spec_pool_lookup (pspec_pool, pspec->name, G_OBJECT_CLASS_TYPE (class), FALSE))
     {
       g_warning (G_STRLOC ": class `%s' already contains a property named `%s'",
@@ -328,11 +294,8 @@ g_object_class_install_property (GObjectClass *class,
 
   g_param_spec_ref (pspec);
   g_param_spec_sink (pspec);
-  g_param_spec_set_qdata (pspec, quark_property_id, GUINT_TO_POINTER (property_id));
+  PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
   g_param_spec_pool_insert (pspec_pool, pspec, G_OBJECT_CLASS_TYPE (class));
-  i = class->n_property_specs++;
-  class->property_specs = g_renew (GParamSpec*, class->property_specs, class->n_property_specs);
-  class->property_specs[i] = pspec;
   if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
     class->construct_properties = g_slist_prepend (class->construct_properties, pspec);
 
@@ -357,39 +320,22 @@ g_object_class_find_property (GObjectClass *class,
                                   TRUE);
 }
 
-static void
-free_notify_queue (gpointer data)
-{
-  NotifyQueue *nqueue = data;
-  
-  g_slist_free (nqueue->pspecs);
-  g_free (nqueue);
-}
-
-static inline NotifyQueue*
-object_freeze_notifies (GObject *object)
+GParamSpec** /* free result */
+g_object_class_list_properties (GObjectClass *class,
+                               guint        *n_properties_p)
 {
-  NotifyQueue *nqueue;
+  GParamSpec **pspecs;
+  guint n;
 
-  nqueue = g_object_get_qdata (object, quark_notify_queue);
-  if (!nqueue)
-    {
-      nqueue = g_new0 (NotifyQueue, 1);
-      g_object_set_qdata_full (object, quark_notify_queue, nqueue, free_notify_queue);
-    }
-  nqueue->freeze_count++;
+  g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL);
 
-  return nqueue;
-}
+  pspecs = g_param_spec_pool_list (pspec_pool,
+                                  G_OBJECT_CLASS_TYPE (class),
+                                  &n);
+  if (n_properties_p)
+    *n_properties_p = n;
 
-static inline void
-object_queue_property (GObject     *object,
-                      GParamSpec  *pspec,
-                      NotifyQueue *nqueue)
-{
-  /* we will dedup later */
-  nqueue->pspecs = g_slist_prepend (nqueue->pspecs, pspec);
-  nqueue->n_pspecs++;
+  return pspecs;
 }
 
 static void
@@ -398,15 +344,13 @@ g_object_init (GObject *object)
   object->ref_count = 1;
   g_datalist_init (&object->qdata);
   
-  /* freeze object's notification queue, g_object_new_valist() takes care of that */
-  object_freeze_notifies (object);
+  /* freeze object's notification queue, g_object_newv() preserves pairedness */
+  g_object_notify_queue_freeze (object, &property_notify_context);
   
 #ifdef G_ENABLE_DEBUG
   IF_DEBUG (OBJECTS)
     {
       G_LOCK (debug_objects);
-      if (!debug_objects_ht)
-       debug_objects_ht = g_hash_table_new (g_direct_hash, NULL);
       debug_objects_count++;
       g_hash_table_insert (debug_objects_ht, object, object);
       G_UNLOCK (debug_objects);
@@ -443,51 +387,25 @@ g_object_do_get_property (GObject     *object,
 }
 
 static void
-g_object_last_unref (GObject *object)
+g_object_real_dispose (GObject *object)
 {
-  g_return_if_fail (object->ref_count > 0);
-  
-  if (object->ref_count == 1)  /* may have been re-referenced meanwhile */
-    G_OBJECT_GET_CLASS (object)->shutdown (object);
-  
-#ifdef G_ENABLE_DEBUG
-  if (g_trap_object_ref == object)
-    G_BREAKPOINT ();
-#endif /* G_ENABLE_DEBUG */
+  guint ref_count;
 
-  object->ref_count -= 1;
-  
-  if (object->ref_count == 0)  /* may have been re-referenced meanwhile */
-    {
-      g_signal_handlers_destroy (object);
-      g_object_set_qdata (object, quark_closure_array, NULL);
-      G_OBJECT_GET_CLASS (object)->finalize (object);
-#ifdef G_ENABLE_DEBUG
-      IF_DEBUG (OBJECTS)
-       {
-         G_LOCK (debug_objects);
-         if (debug_objects_ht)
-           g_assert (g_hash_table_lookup (debug_objects_ht, object) == NULL);
-         G_UNLOCK (debug_objects);
-       }
-#endif /* G_ENABLE_DEBUG */
-      g_type_free_instance ((GTypeInstance*) object);
-    }
-}
+  g_signal_handlers_destroy (object);
+  g_datalist_id_set_data (&object->qdata, quark_closure_array, NULL);
 
-static void
-g_object_shutdown (GObject *object)
-{
-  /* this function needs to be always present for unconditional
-   * chaining, we also might add some code here later.
-   * beware though, subclasses may invoke shutdown() arbitrarily.
+  /* yes, temporarily altering the ref_count is hackish, but that
+   * enforces people not jerking around with weak_ref notifiers
    */
+  ref_count = object->ref_count;
+  object->ref_count = 0;
+  g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
+  object->ref_count = ref_count;
 }
 
 static void
 g_object_finalize (GObject *object)
 {
-  g_signal_handlers_destroy (object);
   g_datalist_clear (&object->qdata);
   
 #ifdef G_ENABLE_DEBUG
@@ -502,40 +420,37 @@ g_object_finalize (GObject *object)
 #endif /* G_ENABLE_DEBUG */
 }
 
-static inline void
-object_thaw_notifies (GObject     *object,
-                     NotifyQueue *nqueue)
+static void
+g_object_last_unref (GObject *object)
 {
-  GParamSpec **pspecs;
-  GSList *slist;
-  guint n_pspecs = 0;
-  
-  nqueue->freeze_count--;
-  if (nqueue->freeze_count)
-    return;
   g_return_if_fail (object->ref_count > 0);
   
-  pspecs = g_new (GParamSpec*, nqueue->n_pspecs);
-  for (slist = nqueue->pspecs; slist; slist = slist->next)
-    {
-      GParamSpec *pspec = slist->data;
-      gint i = 0;
-      
-      /* dedup, make pspecs in the list unique */
-    redo_dedup_check:
-      if (pspecs[i] == pspec)
-       continue;
-      if (++i < n_pspecs)
-       goto redo_dedup_check;
-      
-      pspecs[n_pspecs++] = pspec;
-    }
-  g_object_set_qdata (object, quark_notify_queue, NULL);
+  if (object->ref_count == 1)  /* may have been re-referenced meanwhile */
+    G_OBJECT_GET_CLASS (object)->dispose (object);
   
-  if (n_pspecs)
-    G_OBJECT_GET_CLASS (object)->dispatch_properties_changed (object, n_pspecs, pspecs);
+#ifdef G_ENABLE_DEBUG
+  if (g_trap_object_ref == object)
+    G_BREAKPOINT ();
+#endif /* G_ENABLE_DEBUG */
+
+  object->ref_count -= 1;
   
-  g_free (pspecs);
+  if (object->ref_count == 0)  /* may have been re-referenced meanwhile */
+    {
+      g_signal_handlers_destroy (object);
+      g_datalist_id_set_data (&object->qdata, quark_weak_refs, NULL);
+      G_OBJECT_GET_CLASS (object)->finalize (object);
+#ifdef G_ENABLE_DEBUG
+      IF_DEBUG (OBJECTS)
+       {
+         /* catch objects not chaining finalize handlers */
+         G_LOCK (debug_objects);
+         g_assert (g_hash_table_lookup (debug_objects_ht, object) == NULL);
+         G_UNLOCK (debug_objects);
+       }
+#endif /* G_ENABLE_DEBUG */
+      g_type_free_instance ((GTypeInstance*) object);
+    }
 }
 
 static void
@@ -543,30 +458,30 @@ g_object_dispatch_properties_changed (GObject     *object,
                                      guint        n_pspecs,
                                      GParamSpec **pspecs)
 {
-  g_signal_emit (object, gobject_signals[PROPERTIES_CHANGED], 0, n_pspecs, pspecs);
-}
-
-static void
-g_object_properties_changed (GObject     *object,
-                            guint        n_pspecs,
-                            GParamSpec **pspecs)
-{
   guint i;
 
   for (i = 0; i < n_pspecs; i++)
     g_signal_emit (object, gobject_signals[NOTIFY], g_quark_from_string (pspecs[i]->name), pspecs[i]);
 }
 
-static void
-g_object_notify_property_changed (GObject    *object,
-                                 GParamSpec *pspec)
+void
+g_object_run_dispose (GObject *object)
 {
-  if (0) /* FIXME */
-    g_message ("NOTIFICATION: property `%s' changed on object `%s'",
-              pspec->name,
-              G_OBJECT_TYPE_NAME (object));
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (object->ref_count > 0);
+
+  g_object_ref (object);
+  G_OBJECT_GET_CLASS (object)->dispose (object);
+  g_object_unref (object);
 }
 
+/**
+ * g_object_freeze_notify:
+ * @object: a #GObject
+ * 
+ * Stops emission of "notify" signals on @object. The signals are
+ * queued until g_object_thaw_notify() is called on @object. 
+ **/
 void
 g_object_freeze_notify (GObject *object)
 {
@@ -575,10 +490,17 @@ g_object_freeze_notify (GObject *object)
     return;
 
   g_object_ref (object);
-  object_freeze_notifies (object);
+  g_object_notify_queue_freeze (object, &property_notify_context);
   g_object_unref (object);
 }
 
+/**
+ * g_object_notify:
+ * @object: a #GObject
+ * @property_name: the name of a property installed on the class of @object.
+ * 
+ * Emits a "notify" signal for the property @property_name on @object. 
+ **/
 void
 g_object_notify (GObject     *object,
                 const gchar *property_name)
@@ -602,30 +524,38 @@ g_object_notify (GObject     *object,
               property_name);
   else
     {
-      NotifyQueue *nqueue = object_freeze_notifies (object);
+      GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
 
-      object_queue_property (object, pspec, nqueue);
-      object_thaw_notifies (object, nqueue);
+      g_object_notify_queue_add (object, nqueue, pspec);
+      g_object_notify_queue_thaw (object, nqueue);
     }
   g_object_unref (object);
 }
 
+/**
+ * g_object_thaw_notify:
+ * @object: a #GObject
+ * 
+ * Reverts the effect of a previous call to g_object_freeze_notify().
+ * This causes all queued "notify" signals on @object to be emitted.
+
+ **/
 void
 g_object_thaw_notify (GObject *object)
 {
-  NotifyQueue *nqueue;
+  GObjectNotifyQueue *nqueue;
   
   g_return_if_fail (G_IS_OBJECT (object));
   if (!object->ref_count)
     return;
   
   g_object_ref (object);
-  nqueue = g_object_get_qdata (object, quark_notify_queue);
+  nqueue = g_object_notify_queue_from_object (object, &property_notify_context);
   if (!nqueue || !nqueue->freeze_count)
     g_warning (G_STRLOC ": property-changed notification for %s(%p) is not frozen",
               G_OBJECT_TYPE_NAME (object), object);
   else
-    object_thaw_notifies (object, nqueue);
+    g_object_notify_queue_thaw (object, nqueue);
   g_object_unref (object);
 }
 
@@ -634,79 +564,16 @@ object_get_property (GObject     *object,
                     GParamSpec  *pspec,
                     GValue      *value)
 {
-  GObjectClass *class;
-  
-  class = g_type_class_peek (pspec->owner_type);
+  GObjectClass *class = g_type_class_peek (pspec->owner_type);
   
   class->get_property (object, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
 }
 
-static gchar*
-g_strdup_value_contents (const GValue *value)
-{
-  const gchar *src;
-  gchar *contents;
-
-  g_return_val_if_fail (G_IS_VALUE (value), NULL);
-  
-  if (G_VALUE_HOLDS_STRING (value))
-    {
-      src = g_value_get_string (value);
-      
-      if (!src)
-       contents = g_strdup ("NULL");
-      else
-       {
-         gchar *s = g_strescape (src, NULL);
-
-         contents = g_strdup_printf ("\"%s\"", s);
-         g_free (s);
-       }
-    }
-  else if (g_value_type_transformable (G_VALUE_TYPE (value), G_TYPE_STRING))
-    {
-      GValue tmp_value = { 0, };
-      
-      g_value_init (&tmp_value, G_TYPE_STRING);
-      g_value_transform (value, &tmp_value);
-      if (G_VALUE_HOLDS_ENUM (value) || G_VALUE_HOLDS_FLAGS (value))
-       contents = g_strdup_printf ("((%s) %s)",
-                                   g_type_name (G_VALUE_TYPE (value)),
-                                   g_value_get_string (&tmp_value));
-      else
-       {
-         src = g_value_get_string (&tmp_value);
-         contents = g_strdup (src ? src : "NULL");
-       }
-      g_value_unset (&tmp_value);
-    }
-  else if (g_value_fits_pointer (value))
-    {
-      gpointer p = g_value_peek_pointer (value);
-
-      if (!p)
-       contents = g_strdup ("NULL");
-      else if (G_VALUE_HOLDS_OBJECT (value))
-       contents = g_strdup_printf ("((%s*) %p)", G_OBJECT_TYPE_NAME (p), p);
-      else if (G_VALUE_HOLDS_PARAM (value))
-       contents = g_strdup_printf ("((%s*) %p)", G_PARAM_SPEC_TYPE_NAME (p), p);
-      else if (G_VALUE_HOLDS_BOXED (value))
-       contents = g_strdup_printf ("((%s*) %p)", g_type_name (G_VALUE_TYPE (value)), p);
-      else if (G_VALUE_HOLDS_POINTER (value))
-       contents = g_strdup_printf ("((gpointer) %p)", p);
-      else
-       contents = g_strdup ("???");
-    }
-  else
-    contents = g_strdup ("???");
-  return contents;
-}
-
 static inline void
-object_set_property (GObject      *object,
-                    GParamSpec   *pspec,
-                    const GValue *value,
-                    NotifyQueue  *nqueue)
+object_set_property (GObject             *object,
+                    GParamSpec          *pspec,
+                    const GValue        *value,
+                    GObjectNotifyQueue  *nqueue)
 {
   GValue tmp_value = { 0, };
   GObjectClass *class = g_type_class_peek (pspec->owner_type);
@@ -722,7 +589,7 @@ object_set_property (GObject      *object,
     {
       gchar *contents = g_strdup_value_contents (value);
 
-      g_warning ("value <%s> of type `%s' is invalid for property `%s' of type `%s'",
+      g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
                 contents,
                 G_VALUE_TYPE_NAME (value),
                 pspec->name,
@@ -732,7 +599,7 @@ object_set_property (GObject      *object,
   else
     {
       class->set_property (object, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
-      object_queue_property (object, pspec, nqueue);
+      g_object_notify_queue_add (object, nqueue, pspec);
     }
   g_value_unset (&tmp_value);
 }
@@ -755,42 +622,46 @@ g_object_new (GType          object_type,
 }
 
 gpointer
-g_object_new_valist (GType       object_type,
-                    const gchar *first_property_name,
-                    va_list      var_args)
+g_object_newv (GType       object_type,
+              guint       n_parameters,
+              GParameter *parameters)
 {
-  NotifyQueue *nqueue;
+  GObjectConstructParam *cparams, *oparams;
+  GObjectNotifyQueue *nqueue;
   GObject *object;
   GObjectClass *class;
-  const gchar *name;
-  GObjectConstructParam *cparams = NULL, *nparams = NULL;
-  guint n_cparams = 0, n_nparams = 0;
-  GSList *clist;
-  
+  GSList *slist;
+  guint n_total_cparams = 0, n_cparams = 0, n_oparams = 0, n_cvalues;
+  GValue *cvalues;
+  GList *clist = NULL;
+  guint i;
+
   g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
 
   class = g_type_class_ref (object_type);
-  clist = g_slist_copy (class->construct_properties);
+  for (slist = class->construct_properties; slist; slist = slist->next)
+    {
+      clist = g_list_prepend (clist, slist->data);
+      n_total_cparams += 1;
+    }
 
   /* collect parameters, sort into construction and normal ones */
-  name = first_property_name;
-  while (name)
+  oparams = g_new (GObjectConstructParam, n_parameters);
+  cparams = g_new (GObjectConstructParam, n_total_cparams);
+  for (i = 0; i < n_parameters; i++)
     {
-      GValue *value;
-      GParamSpec *pspec;
-      gchar *error = NULL;
-      
-      pspec = g_param_spec_pool_lookup (pspec_pool,
-                                       name,
-                                       object_type,
-                                       TRUE);
+      GValue *value = &parameters[i].value;
+      GParamSpec *pspec = g_param_spec_pool_lookup (pspec_pool,
+                                                   parameters[i].name,
+                                                   object_type,
+                                                   TRUE);
       if (!pspec)
        {
          g_warning ("%s: object class `%s' has no property named `%s'",
                     G_STRLOC,
                     g_type_name (object_type),
-                    name);
-         break;
+                    parameters[i].name);
+         continue;
        }
       if (!(pspec->flags & G_PARAM_WRITABLE))
        {
@@ -798,103 +669,150 @@ g_object_new_valist (GType        object_type,
                     G_STRLOC,
                     pspec->name,
                     g_type_name (object_type));
-         break;
-       }
-
-      value = g_new (GValue, 1);
-      value->g_type = 0;
-      g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
-      G_VALUE_COLLECT (value, var_args, 0, &error);
-      if (error)
-       {
-         g_warning ("%s: %s", G_STRLOC, error);
-         g_free (error);
-
-         /* we purposely leak the value here, it might not be
-          * in a sane state if an error condition occoured
-          */
-         break;
+         continue;
        }
       if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
        {
-         guint i;
+         GList *list = g_list_find (clist, pspec);
 
-         if (!n_cparams || n_cparams >= PREALLOC_CPARAMS)
-           cparams = g_renew (GObjectConstructParam, cparams, MAX (n_cparams + 1, PREALLOC_CPARAMS));
+         if (!list)
+           {
+             g_warning (G_STRLOC ": construct property \"%s\" for object `%s' can't be set twice",
+                        pspec->name, g_type_name (object_type));
+             continue;
+           }
          cparams[n_cparams].pspec = pspec;
          cparams[n_cparams].value = value;
-         for (i = 0; i < n_cparams; i++)       /* picky, aren't we? ;) */
-           if (cparams[i].pspec == pspec)
-             g_warning (G_STRLOC ": construct property \"%s\" for object `%s' is being set twice",
-                        pspec->name, g_type_name (object_type));
          n_cparams++;
-         clist = g_slist_remove (clist, pspec);   /* FIXME: unique */
+         if (!list->prev)
+           clist = list->next;
+         else
+           list->prev->next = list->next;
+         if (list->next)
+           list->next->prev = list->prev;
+         g_list_free_1 (list);
        }
       else
        {
-         if (!n_nparams || n_nparams >= PREALLOC_CPARAMS)
-           nparams = g_renew (GObjectConstructParam, nparams, MAX (n_nparams + 1, PREALLOC_CPARAMS));
-         nparams[n_nparams].pspec = pspec;
-         nparams[n_nparams].value = value;
-         n_nparams++;
+         oparams[n_oparams].pspec = pspec;
+         oparams[n_oparams].value = value;
+         n_oparams++;
        }
-
-      name = va_arg (var_args, gchar*);
     }
 
-  /* construct object from construction parameters */
+  /* set remaining construction properties to default values */
+  n_cvalues = n_total_cparams - n_cparams;
+  cvalues = g_new (GValue, n_cvalues);
   while (clist)
     {
-      GSList *tmp = clist->next;
+      GList *tmp = clist->next;
       GParamSpec *pspec = clist->data;
-      GValue *value = g_new (GValue, 1);
+      GValue *value = cvalues + n_total_cparams - n_cparams - 1;
 
       value->g_type = 0;
       g_value_init (value, G_PARAM_SPEC_VALUE_TYPE (pspec));
       g_param_value_set_default (pspec, value);
 
-      if (!n_cparams || n_cparams >= PREALLOC_CPARAMS)
-       cparams = g_renew (GObjectConstructParam, cparams, MAX (n_cparams + 1, PREALLOC_CPARAMS));
       cparams[n_cparams].pspec = pspec;
       cparams[n_cparams].value = value;
       n_cparams++;
 
-      g_slist_free_1 (clist);
+      g_list_free_1 (clist);
       clist = tmp;
     }
-  object = class->constructor (object_type, n_cparams, cparams);
+
+  /* construct object from construction parameters */
+  object = class->constructor (object_type, n_total_cparams, cparams);
 
   /* free construction values */
-  while (n_cparams--)
-    {
-      g_value_unset (cparams[n_cparams].value);
-      g_free (cparams[n_cparams].value);
-    }
   g_free (cparams);
+  while (n_cvalues--)
+    g_value_unset (cvalues + n_cvalues);
+  g_free (cvalues);
   
   /* release g_object_init() notification queue freeze_count */
-  nqueue = object_freeze_notifies (object);
-  nqueue->freeze_count--;
+  nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
+  g_object_notify_queue_thaw (object, nqueue);
   
   /* set remaining properties */
-  cparams = nparams;
-  while (n_nparams--)
+  for (i = 0; i < n_oparams; i++)
+    object_set_property (object, oparams[i].pspec, oparams[i].value, nqueue);
+  g_free (oparams);
+
+  g_type_class_unref (class);
+
+  /* release our own freeze count and handle notifications */
+  g_object_notify_queue_thaw (object, nqueue);
+  
+  return object;
+}
+
+GObject*
+g_object_new_valist (GType       object_type,
+                    const gchar *first_property_name,
+                    va_list      var_args)
+{
+  GObjectClass *class;
+  GParameter *params;
+  const gchar *name;
+  GObject *object;
+  guint n_params = 0, n_alloced_params = 16;
+  
+  g_return_val_if_fail (G_TYPE_IS_OBJECT (object_type), NULL);
+
+  if (!first_property_name)
+    return g_object_newv (object_type, 0, NULL);
+
+  class = g_type_class_ref (object_type);
+
+  params = g_new (GParameter, n_alloced_params);
+  name = first_property_name;
+  while (name)
     {
-      GValue *value = nparams->value;
-      GParamSpec *pspec = nparams->pspec;
+      gchar *error = NULL;
+      GParamSpec *pspec = g_param_spec_pool_lookup (pspec_pool,
+                                                   name,
+                                                   object_type,
+                                                   TRUE);
+      if (!pspec)
+       {
+         g_warning ("%s: object class `%s' has no property named `%s'",
+                    G_STRLOC,
+                    g_type_name (object_type),
+                    name);
+         break;
+       }
+      if (n_params >= n_alloced_params)
+       {
+         n_alloced_params += 16;
+         params = g_renew (GParameter, params, n_alloced_params);
+       }
+      params[n_params].name = name;
+      params[n_params].value.g_type = 0;
+      g_value_init (&params[n_params].value, G_PARAM_SPEC_VALUE_TYPE (pspec));
+      G_VALUE_COLLECT (&params[n_params].value, var_args, 0, &error);
+      if (error)
+       {
+         g_warning ("%s: %s", G_STRLOC, error);
+         g_free (error);
 
-      nparams++;
-      object_set_property (object, pspec, value, nqueue);
-      g_value_unset (value);
-      g_free (value);
+         /* we purposely leak the value here, it might not be
+          * in a sane state if an error condition occoured
+          */
+         break;
+       }
+      n_params++;
+      name = va_arg (var_args, gchar*);
     }
-  g_free (cparams);
+
+  object = g_object_newv (object_type, n_params, params);
+
+  while (n_params--)
+    g_value_unset (&params[n_params].value);
+  g_free (params);
 
   g_type_class_unref (class);
 
-  /* release our own freeze count and handle notifications */
-  object_thaw_notifies (object, nqueue);
-  
   return object;
 }
 
@@ -911,7 +829,7 @@ g_object_constructor (GType                  type,
   /* set construction parameters */
   if (n_construct_properties)
     {
-      NotifyQueue *nqueue = object_freeze_notifies (object);
+      GObjectNotifyQueue *nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
       
       /* set construct properties */
       while (n_construct_properties--)
@@ -922,9 +840,9 @@ g_object_constructor (GType                  type,
          construct_params++;
          object_set_property (object, pspec, value, nqueue);
        }
-      nqueue->freeze_count--;
+      g_object_notify_queue_thaw (object, nqueue);
       /* the notification queue is still frozen from g_object_init(), so
-       * we don't need to handle it here, g_object_new_valist() takes
+       * we don't need to handle it here, g_object_newv() takes
        * care of that
        */
     }
@@ -937,13 +855,13 @@ g_object_set_valist (GObject       *object,
                     const gchar *first_property_name,
                     va_list      var_args)
 {
-  NotifyQueue *nqueue;
+  GObjectNotifyQueue *nqueue;
   const gchar *name;
   
   g_return_if_fail (G_IS_OBJECT (object));
   
   g_object_ref (object);
-  nqueue = object_freeze_notifies (object);
+  nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
   
   name = first_property_name;
   while (name)
@@ -993,7 +911,7 @@ g_object_set_valist (GObject         *object,
       name = va_arg (var_args, gchar*);
     }
 
-  object_thaw_notifies (object, nqueue);
+  g_object_notify_queue_thaw (object, nqueue);
   g_object_unref (object);
 }
 
@@ -1041,15 +959,12 @@ g_object_get_valist (GObject      *object,
       
       object_get_property (object, pspec, &value);
       
-      G_VALUE_LCOPY (&value, var_args, G_VALUE_NOCOPY_CONTENTS, &error);
+      G_VALUE_LCOPY (&value, var_args, 0, &error);
       if (error)
        {
          g_warning ("%s: %s", G_STRLOC, error);
          g_free (error);
-         
-         /* we purposely leak the value here, it might not be
-          * in a sane state if an error condition occoured
-          */
+         g_value_unset (&value);
          break;
        }
       
@@ -1061,7 +976,7 @@ g_object_get_valist (GObject        *object,
   g_object_unref (object);
 }
 
-gpointer
+void
 g_object_set (gpointer     _object,
              const gchar *first_property_name,
              ...)
@@ -1069,13 +984,11 @@ g_object_set (gpointer     _object,
   GObject *object = _object;
   va_list var_args;
   
-  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+  g_return_if_fail (G_IS_OBJECT (object));
   
   va_start (var_args, first_property_name);
   g_object_set_valist (object, first_property_name, var_args);
   va_end (var_args);
-
-  return object;
 }
 
 void
@@ -1098,7 +1011,7 @@ g_object_set_property (GObject        *object,
                       const gchar  *property_name,
                       const GValue *value)
 {
-  NotifyQueue *nqueue;
+  GObjectNotifyQueue *nqueue;
   GParamSpec *pspec;
   
   g_return_if_fail (G_IS_OBJECT (object));
@@ -1106,20 +1019,21 @@ g_object_set_property (GObject      *object,
   g_return_if_fail (G_IS_VALUE (value));
   
   g_object_ref (object);
-  nqueue = object_freeze_notifies (object);
+  nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
   
   pspec = g_param_spec_pool_lookup (pspec_pool,
                                    property_name,
                                    G_OBJECT_TYPE (object),
                                    TRUE);
   if (!pspec)
-    g_warning ("object class `%s' has no property named `%s'",
+    g_warning ("%s: object class `%s' has no property named `%s'",
+              G_STRLOC,
               G_OBJECT_TYPE_NAME (object),
               property_name);
   else
     object_set_property (object, pspec, value, nqueue);
   
-  object_thaw_notifies (object, nqueue);
+  g_object_notify_queue_thaw (object, nqueue);
   g_object_unref (object);
 }
 
@@ -1141,7 +1055,8 @@ g_object_get_property (GObject       *object,
                                    G_OBJECT_TYPE (object),
                                    TRUE);
   if (!pspec)
-    g_warning ("object class `%s' has no property named `%s'",
+    g_warning ("%s: object class `%s' has no property named `%s'",
+              G_STRLOC,
               G_OBJECT_TYPE_NAME (object),
               property_name);
   else
@@ -1157,10 +1072,11 @@ g_object_get_property (GObject     *object,
        }
       else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
        {
-         g_warning ("can't retrive property `%s' of type `%s' as value of type `%s'",
+         g_warning ("can't retrieve property `%s' of type `%s' as value of type `%s'",
                     pspec->name,
                     g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
                     G_VALUE_TYPE_NAME (value));
+         g_object_unref (object);
          return;
        }
       else
@@ -1193,26 +1109,42 @@ g_object_connect (gpointer     _object,
   va_start (var_args, signal_spec);
   while (signal_spec)
     {
-      gpointer callback = va_arg (var_args, gpointer);
+      GCallback callback = va_arg (var_args, GCallback);
       gpointer data = va_arg (var_args, gpointer);
-      guint sid;
+      gulong sid;
 
       if (strncmp (signal_spec, "signal::", 8) == 0)
        sid = g_signal_connect_data (object, signal_spec + 8,
                                     callback, data, NULL,
-                                    FALSE, FALSE);
+                                    0);
+      else if (strncmp (signal_spec, "object_signal::", 15) == 0)
+       sid = g_signal_connect_object (object, signal_spec + 15,
+                                      callback, data,
+                                      0);
       else if (strncmp (signal_spec, "swapped_signal::", 16) == 0)
        sid = g_signal_connect_data (object, signal_spec + 16,
                                     callback, data, NULL,
-                                    TRUE, FALSE);
+                                    G_CONNECT_SWAPPED);
+      else if (strncmp (signal_spec, "swapped_object_signal::", 23) == 0)
+       sid = g_signal_connect_object (object, signal_spec + 23,
+                                      callback, data,
+                                      G_CONNECT_SWAPPED);
       else if (strncmp (signal_spec, "signal_after::", 14) == 0)
        sid = g_signal_connect_data (object, signal_spec + 14,
                                     callback, data, NULL,
-                                    FALSE, TRUE);
+                                    G_CONNECT_AFTER);
+      else if (strncmp (signal_spec, "object_signal_after::", 21) == 0)
+       sid = g_signal_connect_object (object, signal_spec + 21,
+                                      callback, data,
+                                      G_CONNECT_AFTER);
       else if (strncmp (signal_spec, "swapped_signal_after::", 22) == 0)
        sid = g_signal_connect_data (object, signal_spec + 22,
                                     callback, data, NULL,
-                                    TRUE, TRUE);
+                                    G_CONNECT_SWAPPED | G_CONNECT_AFTER);
+      else if (strncmp (signal_spec, "swapped_object_signal_after::", 29) == 0)
+       sid = g_signal_connect_object (object, signal_spec + 29,
+                                      callback, data,
+                                      G_CONNECT_SWAPPED | G_CONNECT_AFTER);
       else
        {
          g_warning ("%s: invalid signal spec \"%s\"", G_STRLOC, signal_spec);
@@ -1225,7 +1157,7 @@ g_object_connect (gpointer     _object,
   return object;
 }
 
-gpointer
+void
 g_object_disconnect (gpointer     _object,
                     const gchar *signal_spec,
                     ...)
@@ -1233,13 +1165,13 @@ g_object_disconnect (gpointer     _object,
   GObject *object = _object;
   va_list var_args;
 
-  g_return_val_if_fail (G_IS_OBJECT (object), NULL);
-  g_return_val_if_fail (object->ref_count > 0, object);
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (object->ref_count > 0);
 
   va_start (var_args, signal_spec);
   while (signal_spec)
     {
-      gpointer callback = va_arg (var_args, gpointer);
+      GCallback callback = va_arg (var_args, GCallback);
       gpointer data = va_arg (var_args, gpointer);
       guint sid = 0, detail = 0, mask = 0;
 
@@ -1264,13 +1196,119 @@ g_object_disconnect (gpointer     _object,
        g_warning ("%s: invalid signal name \"%s\"", G_STRLOC, signal_spec);
       else if (!g_signal_handlers_disconnect_matched (object, mask | (detail ? G_SIGNAL_MATCH_DETAIL : 0),
                                                      sid, detail,
-                                                     NULL, callback, data))
+                                                     NULL, (gpointer)callback, data))
        g_warning (G_STRLOC ": signal handler %p(%p) is not connected", callback, data);
       signal_spec = va_arg (var_args, gchar*);
     }
   va_end (var_args);
+}
 
-  return object;
+typedef struct {
+  GObject *object;
+  guint n_weak_refs;
+  struct {
+    GWeakNotify notify;
+    gpointer    data;
+  } weak_refs[1];  /* flexible array */
+} WeakRefStack;
+
+static void
+weak_refs_notify (gpointer data)
+{
+  WeakRefStack *wstack = data;
+  guint i;
+
+  for (i = 0; i < wstack->n_weak_refs; i++)
+    wstack->weak_refs[i].notify (wstack->weak_refs[i].data, wstack->object);
+  g_free (wstack);
+}
+
+void
+g_object_weak_ref (GObject    *object,
+                  GWeakNotify notify,
+                  gpointer    data)
+{
+  WeakRefStack *wstack;
+  guint i;
+  
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (notify != NULL);
+  g_return_if_fail (object->ref_count >= 1);
+
+  wstack = g_datalist_id_remove_no_notify (&object->qdata, quark_weak_refs);
+  if (wstack)
+    {
+      i = wstack->n_weak_refs++;
+      wstack = g_realloc (wstack, sizeof (*wstack) + sizeof (wstack->weak_refs[0]) * i);
+    }
+  else
+    {
+      wstack = g_renew (WeakRefStack, NULL, 1);
+      wstack->object = object;
+      wstack->n_weak_refs = 1;
+      i = 0;
+    }
+  wstack->weak_refs[i].notify = notify;
+  wstack->weak_refs[i].data = data;
+  g_datalist_id_set_data_full (&object->qdata, quark_weak_refs, wstack, weak_refs_notify);
+}
+
+void
+g_object_weak_unref (GObject    *object,
+                    GWeakNotify notify,
+                    gpointer    data)
+{
+  WeakRefStack *wstack;
+  gboolean found_one = FALSE;
+
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (notify != NULL);
+
+  wstack = g_datalist_id_get_data (&object->qdata, quark_weak_refs);
+  if (wstack)
+    {
+      guint i;
+
+      for (i = 0; i < wstack->n_weak_refs; i++)
+       if (wstack->weak_refs[i].notify == notify &&
+           wstack->weak_refs[i].data == data)
+         {
+           found_one = TRUE;
+           wstack->n_weak_refs -= 1;
+           if (i != wstack->n_weak_refs)
+             {
+               wstack->weak_refs[i].notify = wstack->weak_refs[wstack->n_weak_refs].notify;
+               wstack->weak_refs[i].data = wstack->weak_refs[wstack->n_weak_refs].data;
+             }
+           break;
+         }
+    }
+  if (!found_one)
+    g_warning (G_STRLOC ": couldn't find weak ref %p(%p)", notify, data);
+}
+
+void
+g_object_add_weak_pointer (GObject  *object, 
+                           gpointer *weak_pointer_location)
+{
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (weak_pointer_location != NULL);
+
+  g_object_weak_ref (object, 
+                     (GWeakNotify) g_nullify_pointer, 
+                     weak_pointer_location);
+}
+
+void
+g_object_remove_weak_pointer (GObject  *object, 
+                              gpointer *weak_pointer_location)
+{
+  g_return_if_fail (G_IS_OBJECT (object));
+  g_return_if_fail (weak_pointer_location != NULL);
+
+  g_object_weak_unref (object, 
+                       (GWeakNotify) g_nullify_pointer, 
+                       weak_pointer_location);
 }
 
 gpointer
@@ -1339,7 +1377,8 @@ g_object_set_qdata_full (GObject       *object,
   g_return_if_fail (G_IS_OBJECT (object));
   g_return_if_fail (quark > 0);
   
-  g_datalist_id_set_data_full (&object->qdata, quark, data, data ? destroy : NULL);
+  g_datalist_id_set_data_full (&object->qdata, quark, data,
+                              data ? destroy : (GDestroyNotify) NULL);
 }
 
 gpointer
@@ -1386,7 +1425,8 @@ g_object_set_data_full (GObject       *object,
   g_return_if_fail (G_IS_OBJECT (object));
   g_return_if_fail (key != NULL);
 
-  g_datalist_id_set_data_full (&object->qdata, g_quark_from_string (key), data, data ? destroy : NULL);
+  g_datalist_id_set_data_full (&object->qdata, g_quark_from_string (key), data,
+                              data ? destroy : (GDestroyNotify) NULL);
 }
 
 gpointer
@@ -1495,8 +1535,8 @@ g_value_object_lcopy_value (const GValue *value,
 }
 
 void
-g_value_set_object (GValue  *value,
-                   GObject *v_object)
+g_value_set_object (GValue   *value,
+                   gpointer  v_object)
 {
   g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
   
@@ -1516,6 +1556,27 @@ g_value_set_object (GValue  *value,
     }
 }
 
+void
+g_value_set_object_take_ownership (GValue  *value,
+                                  gpointer v_object)
+{
+  g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
+
+  if (value->data[0].v_pointer)
+    {
+      g_object_unref (value->data[0].v_pointer);
+      value->data[0].v_pointer = NULL;
+    }
+
+  if (v_object)
+    {
+      g_return_if_fail (G_IS_OBJECT (v_object));
+      g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value)));
+
+      value->data[0].v_pointer = v_object; /* we take over the reference count */
+    }
+}
+
 gpointer
 g_value_get_object (const GValue *value)
 {
@@ -1532,13 +1593,25 @@ g_value_dup_object (const GValue *value)
   return value->data[0].v_pointer ? g_object_ref (value->data[0].v_pointer) : NULL;
 }
 
-guint
-g_signal_connect_object (gpointer     instance,
-                        const gchar *detailed_signal,
-                        GCallback    c_handler,
-                        gpointer     gobject,
-                        gboolean     swapped,
-                        gboolean     after)
+/**
+ * g_signal_connect_object:
+ * @instance: the instance to connect to.
+ * @detailed_signal: a string of the form "signal-name::detail".
+ * @c_handler: the #GCallback to connect.
+ * @gobject: the object to pass as data to @c_handler.
+ * @connect_flags: a combination of #GConnnectFlags.
+ * 
+ * This is similar to g_signal_connect_data(), but uses a closure which
+ * ensures that the object stays alive during the call to @c_handler.
+ * 
+ * Return value: the handler id.
+ **/
+gulong
+g_signal_connect_object (gpointer      instance,
+                        const gchar  *detailed_signal,
+                        GCallback     c_handler,
+                        gpointer      gobject,
+                        GConnectFlags connect_flags)
 {
   g_return_val_if_fail (G_TYPE_CHECK_INSTANCE (instance), 0);
   g_return_val_if_fail (detailed_signal != NULL, 0);
@@ -1550,12 +1623,12 @@ g_signal_connect_object (gpointer     instance,
 
       g_return_val_if_fail (G_IS_OBJECT (gobject), 0);
 
-      closure = (swapped ? g_cclosure_new_object_swap : g_cclosure_new_object) (c_handler, gobject);
+      closure = ((connect_flags & G_CONNECT_SWAPPED) ? g_cclosure_new_object_swap : g_cclosure_new_object) (c_handler, gobject);
 
-      return g_signal_connect_closure (instance, detailed_signal, closure, after);
+      return g_signal_connect_closure (instance, detailed_signal, closure, connect_flags & G_CONNECT_AFTER);
     }
   else
-    return g_signal_connect_data (instance, detailed_signal, c_handler, NULL, NULL, swapped, after);
+    return g_signal_connect_data (instance, detailed_signal, c_handler, NULL, NULL, connect_flags);
 }
 
 typedef struct {
@@ -1563,6 +1636,24 @@ typedef struct {
   guint     n_closures;
   GClosure *closures[1]; /* flexible array */
 } CArray;
+/* don't change this structure without supplying an accessor for
+ * watched closures, e.g.:
+ * GSList* g_object_list_watched_closures (GObject *object)
+ * {
+ *   CArray *carray;
+ *   g_return_val_if_fail (G_IS_OBJECT (object), NULL);
+ *   carray = g_object_get_data (object, "GObject-closure-array");
+ *   if (carray)
+ *     {
+ *       GSList *slist = NULL;
+ *       guint i;
+ *       for (i = 0; i < carray->n_closures; i++)
+ *         slist = g_slist_prepend (slist, carray->closures[i]);
+ *       return slist;
+ *     }
+ *   return NULL;
+ * }
+ */
 
 static void
 object_remove_closure (gpointer  data,
@@ -1597,7 +1688,7 @@ destroy_closure_array (gpointer data)
       /* removing object_remove_closure() upfront is probably faster than
        * letting it fiddle with quark_closure_array which is empty anyways
        */
-      g_closure_remove_inotify (closure, object, object_remove_closure);
+      g_closure_remove_invalidate_notifier (closure, object, object_remove_closure);
       g_closure_invalidate (closure);
     }
   g_free (carray);
@@ -1608,6 +1699,7 @@ g_object_watch_closure (GObject  *object,
                        GClosure *closure)
 {
   CArray *carray;
+  guint i;
   
   g_return_if_fail (G_IS_OBJECT (object));
   g_return_if_fail (closure != NULL);
@@ -1615,27 +1707,25 @@ g_object_watch_closure (GObject  *object,
   g_return_if_fail (closure->in_marshal == FALSE);
   g_return_if_fail (object->ref_count > 0);    /* this doesn't work on finalizing objects */
   
-  g_closure_add_inotify (closure, object, object_remove_closure);
+  g_closure_add_invalidate_notifier (closure, object, object_remove_closure);
   g_closure_add_marshal_guards (closure,
                                object, (GClosureNotify) g_object_ref,
                                object, (GClosureNotify) g_object_unref);
-  carray = g_object_steal_qdata (object, quark_closure_array);
+  carray = g_datalist_id_remove_no_notify (&object->qdata, quark_closure_array);
   if (!carray)
     {
       carray = g_renew (CArray, NULL, 1);
       carray->object = object;
       carray->n_closures = 1;
-      carray->closures[0] = closure;
-      g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
+      i = 0;
     }
   else
     {
-      guint i = carray->n_closures++;
-      
+      i = carray->n_closures++;
       carray = g_realloc (carray, sizeof (*carray) + sizeof (carray->closures[0]) * i);
-      carray->closures[i] = closure;
-      g_object_set_qdata_full (object, quark_closure_array, carray, destroy_closure_array);
     }
+  carray->closures[i] = closure;
+  g_datalist_id_set_data_full (&object->qdata, quark_closure_array, carray, destroy_closure_array);
 }
 
 GClosure*
@@ -1655,9 +1745,8 @@ g_closure_new_object (guint    sizeof_closure,
 
 GClosure*
 g_cclosure_new_object (GCallback callback_func,
-                      gpointer  _object)
+                      GObject  *object)
 {
-  GObject *object = _object;
   GClosure *closure;
 
   g_return_val_if_fail (G_IS_OBJECT (object), NULL);
@@ -1672,9 +1761,8 @@ g_cclosure_new_object (GCallback callback_func,
 
 GClosure*
 g_cclosure_new_object_swap (GCallback callback_func,
-                           gpointer  _object)
+                           GObject  *object)
 {
-  GObject *object = _object;
   GClosure *closure;
 
   g_return_val_if_fail (G_IS_OBJECT (object), NULL);