Index: configure.in
===================================================================
RCS file: /cvs/gnome/glib/configure.in,v
retrieving revision 1.516
diff -u -p -r1.516 configure.in
--- configure.in	3 Jul 2006 08:26:55 -0000	1.516
+++ configure.in	19 Jul 2006 22:36:51 -0000
@@ -186,6 +186,12 @@ AC_ARG_ENABLE(debug,
                              [turn on debugging @<:@default=glib_debug_default@:>@]),,
               enable_debug=glib_debug_default)
 
+AC_ARG_ENABLE(refdbg,
+              AC_HELP_STRING([--enable-refdbg],
+                             [turn on reference debugging (requires valgrind refdbg tool)]),,
+              enable_refdbg=no)
+
+
 AC_ARG_ENABLE(gc_friendly,
               [AC_HELP_STRING([--enable-gc-friendly],
                               [turn on garbage collector friendliness [default=no]])],,
@@ -215,6 +221,18 @@ fi
 AC_DEFINE_UNQUOTED(G_COMPILED_WITH_DEBUGGING, ["${enable_debug}"],
 	[Whether glib was compiled with debugging enabled])
 
+AC_MSG_CHECKING([whether to enable reference debugging facilities])
+if test "x$enable_refdbg" = "xyes"; then
+  AC_MSG_RESULT([yes])
+	PKG_CHECK_MODULES(VALGRIND, [valgrind])
+	CPPFLAGS="$CPPFLAGS $VALGRIND_CFLAGS"
+	AC_CHECK_HEADERS([refdbg.h],,
+	  [AC_MSG_ERROR([*** refdbg not found.])])
+else
+  AC_MSG_RESULT([no])
+fi
+
+
 AC_MSG_CHECKING([whether to enable garbage collector friendliness])
 if test "x$enable_gc_friendly" = "xyes"; then
   AC_DEFINE(ENABLE_GC_FRIENDLY_DEFAULT, 1, [Whether to enable GC friendliness by default])
@@ -2390,6 +2411,12 @@ _______EOF
 _______EOF
 	fi
 
+	echo >>$outfile
+	if test x$g_object_refdbg_enabled = xyes; then
+		cat >>$outfile <<_______EOF
+#define G_OBJECT_REFDBG_ENABLED
+_______EOF
+	fi
 
 	echo >>$outfile
 	if test x$g_mutex_has_default = xyes; then
@@ -2737,6 +2764,8 @@ g_pollnval=$glib_cv_value_POLLNVAL
 g_stack_grows=$glib_cv_stack_grows
 
 g_have_eilseq=$have_eilseq
+
+g_object_refdbg_enabled=$enable_refdbg
 
 case x$have_threads in
 xno)	g_enable_threads_def="#undef";;
Index: gobject/gobject.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gobject.c,v
retrieving revision 1.77
diff -u -p -r1.77 gobject.c
--- gobject/gobject.c	7 Mar 2006 16:15:20 -0000	1.77
+++ gobject/gobject.c	19 Jul 2006 22:37:01 -0000
@@ -32,6 +32,13 @@
 #include	<string.h>
 #include	<signal.h>
 
+#ifdef G_OBJECT_REFDBG_ENABLED
+#include  <refdbg.h>
+#define  __RF(x) x
+#else
+#define  __RF(x)
+#endif
+
 
 #define	PREALLOC_CPARAMS	(8)
 
@@ -567,9 +574,9 @@ g_object_run_dispose (GObject *object)
   g_return_if_fail (G_IS_OBJECT (object));
   g_return_if_fail (object->ref_count > 0);
 
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   G_OBJECT_GET_CLASS (object)->dispose (object);
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -580,9 +587,9 @@ g_object_freeze_notify (GObject *object)
   if (g_atomic_int_get (&object->ref_count) == 0)
     return;
 
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   g_object_notify_queue_freeze (object, &property_notify_context);
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -596,7 +603,7 @@ g_object_notify (GObject     *object,
   if (g_atomic_int_get (&object->ref_count) == 0)
     return;
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   /* We don't need to get the redirect target
    * (by, e.g. calling g_object_class_find_property())
    * because g_object_notify_queue_add() does that
@@ -619,7 +626,7 @@ g_object_notify (GObject     *object,
       g_object_notify_queue_add (object, nqueue, pspec);
       g_object_notify_queue_thaw (object, nqueue);
     }
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -631,14 +638,14 @@ g_object_thaw_notify (GObject *object)
   if (g_atomic_int_get (&object->ref_count) == 0)
     return;
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   nqueue = g_object_notify_queue_from_object (object, &property_notify_context);
   if (!nqueue || !nqueue->freeze_count)
     g_warning ("%s: property-changed notification for %s(%p) is not frozen",
 	       G_STRFUNC, G_OBJECT_TYPE_NAME (object), object);
   else
     g_object_notify_queue_thaw (object, nqueue);
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 static inline void
@@ -1048,7 +1055,7 @@ g_object_set_valist (GObject	 *object,
   
   g_return_if_fail (G_IS_OBJECT (object));
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
   
   name = first_property_name;
@@ -1103,7 +1110,7 @@ g_object_set_valist (GObject	 *object,
     }
 
   g_object_notify_queue_thaw (object, nqueue);
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -1115,7 +1122,7 @@ g_object_get_valist (GObject	 *object,
   
   g_return_if_fail (G_IS_OBJECT (object));
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   
   name = first_property_name;
   
@@ -1164,7 +1171,7 @@ g_object_get_valist (GObject	 *object,
       name = va_arg (var_args, gchar*);
     }
   
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -1209,7 +1216,7 @@ g_object_set_property (GObject	    *obje
   g_return_if_fail (property_name != NULL);
   g_return_if_fail (G_IS_VALUE (value));
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
   
   pspec = g_param_spec_pool_lookup (pspec_pool,
@@ -1233,7 +1240,7 @@ g_object_set_property (GObject	    *obje
     object_set_property (object, pspec, value, nqueue);
   
   g_object_notify_queue_thaw (object, nqueue);
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 void
@@ -1247,7 +1254,7 @@ g_object_get_property (GObject	   *objec
   g_return_if_fail (property_name != NULL);
   g_return_if_fail (G_IS_VALUE (value));
   
-  g_object_ref (object);
+  g_object_ref_and_context (object);
   
   pspec = g_param_spec_pool_lookup (pspec_pool,
 				    property_name,
@@ -1280,7 +1287,7 @@ g_object_get_property (GObject	   *objec
 		     G_STRFUNC, pspec->name,
 		     g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
 		     G_VALUE_TYPE_NAME (value));
-	  g_object_unref (object);
+	  g_object_unref_and_context (object);
 	  return;
 	}
       else
@@ -1296,7 +1303,7 @@ g_object_get_property (GObject	   *objec
 	}
     }
   
-  g_object_unref (object);
+  g_object_unref_and_context (object);
 }
 
 gpointer
@@ -1564,7 +1571,21 @@ g_object_ref_sink (gpointer _object)
   g_object_ref (object);
   was_floating = floating_flag_handler (object, -1);
   if (was_floating)
-    g_object_unref (object);
+    g_object_unref_with_context (object, object);
+  return object;
+}
+
+gpointer
+g_object_ref_sink_with_context (gpointer _object, gpointer ctx)
+{
+  GObject *object = _object;
+  gboolean was_floating;
+  g_return_val_if_fail (G_IS_OBJECT (object), object);
+  g_return_val_if_fail (object->ref_count >= 1, object);
+  g_object_ref_with_context (object, ctx);
+  was_floating = floating_flag_handler (object, -1);
+  if (was_floating)
+    g_object_unref_with_context (object, object);
   return object;
 }
 
@@ -1612,7 +1633,7 @@ g_object_add_toggle_ref (GObject       *
   g_return_if_fail (notify != NULL);
   g_return_if_fail (object->ref_count >= 1);
 
-  g_object_ref (object);
+  g_object_ref_with_context (object, notify);
 
   tstack = g_datalist_id_remove_no_notify (&object->qdata, quark_toggle_refs);
   if (tstack)
@@ -1668,7 +1689,7 @@ g_object_remove_toggle_ref (GObject     
 	    if (tstack->n_toggle_refs == 0)
 	      g_datalist_unset_flags (&object->qdata, OBJECT_HAS_TOGGLE_REF_FLAG);
 
-	    g_object_unref (object);
+	    g_object_unref_with_context (object, notify);
 	    
 	    break;
 	  }
@@ -1697,6 +1718,8 @@ g_object_ref (gpointer _object)
 
   if (old_val == 1 && OBJECT_HAS_TOGGLE_REF (object))
     toggle_refs_notify (object, FALSE);
+
+  __RF (REFDBG_INC_REF (object));
   
   return object;
 }
@@ -1716,6 +1739,8 @@ g_object_unref (gpointer _object)
     G_BREAKPOINT ();
 #endif  /* G_ENABLE_DEBUG */
 
+  __RF (REFDBG_DEC_REF (object));
+
   /* here we want to atomically do: if (ref_count>1) { ref_count--; return; } */
  retry_atomic_decrement1:
   old_ref = g_atomic_int_get (&object->ref_count);
@@ -1774,6 +1799,22 @@ g_object_unref (gpointer _object)
     }
 }
 
+
+gpointer g_object_ref_with_context_glib_use_only(gpointer ptr, gpointer ctx)
+{
+  __RF(REFDBG_GET_CTX (ptr, ctx, TRUE));
+  return g_object_ref (ptr);
+}
+void g_object_ref_set_context_glib_use_only(gpointer ptr, gpointer old, gpointer ctx)
+{
+  __RF(REFDBG_MOVE_CTX (ptr, old, ctx));
+}
+void g_object_unref_with_context_glib_use_only(gpointer ptr, gpointer ctx)
+{
+  __RF(REFDBG_GET_CTX (ptr, ctx, FALSE));
+  g_object_unref (ptr);
+}
+
 gpointer
 g_object_get_qdata (GObject *object,
 		    GQuark   quark)
@@ -1879,7 +1920,7 @@ static void
 g_value_object_free_value (GValue *value)
 {
   if (value->data[0].v_pointer)
-    g_object_unref (value->data[0].v_pointer);
+    g_object_unref_and_context (value->data[0].v_pointer);
 }
 
 static void
@@ -1887,7 +1928,8 @@ g_value_object_copy_value (const GValue 
 			   GValue	*dest_value)
 {
   if (src_value->data[0].v_pointer)
-    dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
+		dest_value->data[0].v_pointer = g_object_ref_with_context (src_value->data[0].v_pointer,
+				&dest_value->data[0].v_pointer);
   else
     dest_value->data[0].v_pointer = NULL;
 }
@@ -1897,7 +1939,8 @@ g_value_object_transform_value (const GV
 				GValue       *dest_value)
 {
   if (src_value->data[0].v_pointer && g_type_is_a (G_OBJECT_TYPE (src_value->data[0].v_pointer), G_VALUE_TYPE (dest_value)))
-    dest_value->data[0].v_pointer = g_object_ref (src_value->data[0].v_pointer);
+    dest_value->data[0].v_pointer = g_object_ref_with_context (src_value->data[0].v_pointer,
+				&dest_value->data[0].v_pointer);
   else
     dest_value->data[0].v_pointer = NULL;
 }
@@ -1931,7 +1974,7 @@ g_value_object_collect_value (GValue	  *
 			    "'",
 			    NULL);
       /* never honour G_VALUE_NOCOPY_CONTENTS for ref-counted types */
-      value->data[0].v_pointer = g_object_ref (object);
+      value->data[0].v_pointer = g_object_ref_with_context (object, &value->data[0].v_pointer);
     }
   else
     value->data[0].v_pointer = NULL;
@@ -1969,6 +2012,8 @@ g_value_set_object (GValue   *value,
   g_return_if_fail (G_VALUE_HOLDS_OBJECT (value));
 
   old = value->data[0].v_pointer;
+  if(old == v_object)
+    return;
   
   if (v_object)
     {
@@ -1976,13 +2021,13 @@ g_value_set_object (GValue   *value,
       g_return_if_fail (g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value)));
 
       value->data[0].v_pointer = v_object;
-      g_object_ref (value->data[0].v_pointer);
+      g_object_ref_and_context (value->data[0].v_pointer);
     }
   else
     value->data[0].v_pointer = NULL;
   
   if (old)
-    g_object_unref (old);
+    g_object_unref_with_context (old, &value->data[0].v_pointer);
 }
 
 void
@@ -2000,7 +2045,7 @@ g_value_take_object (GValue  *value,
 
   if (value->data[0].v_pointer)
     {
-      g_object_unref (value->data[0].v_pointer);
+      g_object_unref_and_context (value->data[0].v_pointer);
       value->data[0].v_pointer = NULL;
     }
 
Index: gobject/gobject.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gobject.h,v
retrieving revision 1.37
diff -u -p -r1.37 gobject.h
--- gobject/gobject.h	18 Jan 2006 16:03:57 -0000	1.37
+++ gobject/gobject.h	19 Jul 2006 22:37:02 -0000
@@ -278,6 +278,29 @@ G_STMT_START { \
 #define G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec) \
     G_OBJECT_WARN_INVALID_PSPEC ((object), "property", (property_id), (pspec))
 
+#ifdef G_OBJECT_REFDBG_ENABLED
+gpointer    g_object_ref_with_context_glib_use_only   (gpointer object, gpointer context);
+void    g_object_ref_set_context_glib_use_only   (gpointer object, gpointer old, gpointer context);
+gpointer    g_object_ref_sink_with_context_glib_use_only   (gpointer object, gpointer context);
+void        g_object_unref_with_context_glib_use_only (gpointer object, gpointer context);
+#define g_object_ref_with_context(obj, ctx) g_object_ref_with_context_glib_use_only (obj, ctx)
+#define g_object_ref_set_context(obj, old, ctx) g_object_ref_set_context_glib_use_only (obj, old, ctx)
+#define g_object_ref_sink_with_context(obj, ctx) g_object_ref_sink_with_context_glib_use_only (obj, ctx)
+#define g_object_unref_with_context(obj, ctx) g_object_unref_with_context_glib_use_only (obj, ctx)
+#else
+#define g_object_ref_with_context(obj, ctx) g_object_ref (obj)
+#define g_object_ref_set_context(obj, old, ctx) (void)0
+#define g_object_ref_sink_with_context(obj, ctx) g_object_ref_sink (obj)
+#define g_object_unref_with_context(obj, ctx) g_object_unref (obj)
+#endif
+
+#define g_object_ref_and_context(obj) \
+	g_object_ref_with_context(obj, &obj)
+#define g_object_ref_sink_and_context(obj) \
+	g_object_ref_sink_with_context(obj, &obj)
+#define g_object_unref_and_context(obj) \
+	g_object_unref_with_context(obj, &obj)
+
 G_END_DECLS
 
 #endif /* __G_OBJECT_H__ */
Index: gobject/gobject.symbols
===================================================================
RCS file: /cvs/gnome/glib/gobject/gobject.symbols,v
retrieving revision 1.18
diff -u -p -r1.18 gobject.symbols
--- gobject/gobject.symbols	23 Apr 2006 04:21:08 -0000	1.18
+++ gobject/gobject.symbols	19 Jul 2006 22:37:02 -0000
@@ -135,9 +135,12 @@ g_object_new_valist
 g_object_notify
 g_object_is_floating
 g_object_ref_sink
+g_object_ref_sink_with_context_glib_use_only
 g_object_force_floating
 g_object_ref
+g_object_ref_with_context_glib_use_only
 g_object_unref
+g_object_unref_with_context_glib_use_only
 g_object_remove_weak_pointer
 g_object_run_dispose
 g_object_set G_GNUC_NULL_TERMINATED
@@ -203,8 +206,10 @@ g_param_spec_get_redirect_target
 g_param_spec_internal
 g_param_type_register_static
 g_param_spec_ref
+g_param_spec_ref_with_context_glib_use_only
 g_param_spec_ref_sink
 g_param_spec_unref
+g_param_spec_unref_with_context_glib_use_only
 g_param_spec_sink
 g_param_spec_steal_qdata
 g_param_spec_set_qdata
Index: gobject/gparam.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gparam.c,v
retrieving revision 1.41
diff -u -p -r1.41 gparam.c
--- gobject/gparam.c	23 Nov 2005 17:54:41 -0000	1.41
+++ gobject/gparam.c	19 Jul 2006 22:37:03 -0000
@@ -29,6 +29,14 @@
 #include	<string.h>
 
 
+#ifdef G_OBJECT_REFDBG_ENABLED
+#include <refdbg.h>
+#define  __RF(x) x
+#else
+#define  __RF(x)
+#endif
+
+
 
 /* --- defines --- */
 #define	G_PARAM_USER_MASK			(~0 << G_PARAM_USER_SHIFT)
@@ -172,6 +180,8 @@ g_param_spec_ref (GParamSpec *pspec)
 
   g_atomic_int_inc (&pspec->ref_count);
 
+  __RF (REFDBG_INC_REF (pspec));
+
   return pspec;
 }
 
@@ -183,6 +193,8 @@ g_param_spec_unref (GParamSpec *pspec)
   g_return_if_fail (G_IS_PARAM_SPEC (pspec));
   g_return_if_fail (pspec->ref_count > 0);
 
+  __RF (REFDBG_DEC_REF (pspec));
+
   is_zero = g_atomic_int_dec_and_test (&pspec->ref_count);
 
   if (G_UNLIKELY (is_zero))
@@ -191,6 +203,17 @@ g_param_spec_unref (GParamSpec *pspec)
     }
 }
 
+GParamSpec *g_param_spec_ref_with_context_glib_use_only(GParamSpec *ptr, gpointer ctx)
+{
+  __RF (REFDBG_GET_CTX (ptr, ctx, TRUE));
+  return g_param_spec_ref (ptr);
+}
+void g_param_spec_unref_with_context_glib_use_only(GParamSpec *ptr, gpointer ctx)
+{
+  __RF (REFDBG_GET_CTX (ptr, ctx, FALSE));
+  g_param_spec_unref (ptr);
+}
+
 void
 g_param_spec_sink (GParamSpec *pspec)
 {
@@ -514,7 +537,7 @@ static void
 value_param_free_value (GValue *value)
 {
   if (value->data[0].v_pointer)
-    g_param_spec_unref (value->data[0].v_pointer);
+    g_param_spec_unref_and_context (value->data[0].v_pointer);
 }
 
 static void
@@ -522,7 +545,7 @@ value_param_copy_value (const GValue *sr
 			GValue       *dest_value)
 {
   if (src_value->data[0].v_pointer)
-    dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer);
+    dest_value->data[0].v_pointer = g_param_spec_ref_with_context (src_value->data[0].v_pointer, dest_value->data[0].v_pointer);
   else
     dest_value->data[0].v_pointer = NULL;
 }
@@ -533,7 +556,7 @@ value_param_transform_value (const GValu
 {
   if (src_value->data[0].v_pointer &&
       g_type_is_a (G_PARAM_SPEC_TYPE (dest_value->data[0].v_pointer), G_VALUE_TYPE (dest_value)))
-    dest_value->data[0].v_pointer = g_param_spec_ref (src_value->data[0].v_pointer);
+    dest_value->data[0].v_pointer = g_param_spec_ref_with_context (src_value->data[0].v_pointer, &dest_value->data[0].v_pointer);
   else
     dest_value->data[0].v_pointer = NULL;
 }
@@ -566,7 +589,7 @@ value_param_collect_value (GValue      *
 			    G_VALUE_TYPE_NAME (value),
 			    "'",
 			    NULL);
-      value->data[0].v_pointer = g_param_spec_ref (param);
+      value->data[0].v_pointer = g_param_spec_ref_with_context (param, &value->data[0].v_pointer);
     }
   else
     value->data[0].v_pointer = NULL;
@@ -590,7 +613,7 @@ value_param_lcopy_value (const GValue *v
   else if (collect_flags & G_VALUE_NOCOPY_CONTENTS)
     *param_p = value->data[0].v_pointer;
   else
-    *param_p = g_param_spec_ref (value->data[0].v_pointer);
+    *param_p = g_param_spec_ref_with_context (value->data[0].v_pointer, param_p);
 
   return NULL;
 }
@@ -662,7 +685,7 @@ g_param_spec_pool_insert (GParamSpecPool
 	}
       
       pspec->owner_type = owner_type;
-      g_param_spec_ref (pspec);
+      g_param_spec_ref_with_context (pspec, pool->hash_table);
       g_hash_table_insert (pool->hash_table, pspec, pspec);
       G_SUNLOCK (&pool->smutex);
     }
@@ -683,7 +706,7 @@ g_param_spec_pool_remove (GParamSpecPool
     {
       G_SLOCK (&pool->smutex);
       if (g_hash_table_remove (pool->hash_table, pspec))
-	g_param_spec_unref (pspec);
+	g_param_spec_unref_with_context (pspec, pool->hash_table);
       else
 	g_warning (G_STRLOC ": attempt to remove unknown pspec `%s' from pool", pspec->name);
       G_SUNLOCK (&pool->smutex);
@@ -1085,11 +1108,14 @@ g_value_set_param (GValue     *value,
   if (param)
     g_return_if_fail (G_IS_PARAM_SPEC (param));
 
+  if (value->data[0].v_pointer == param)
+    return;
+
   if (value->data[0].v_pointer)
-    g_param_spec_unref (value->data[0].v_pointer);
+    g_param_spec_unref_and_context (value->data[0].v_pointer);
   value->data[0].v_pointer = param;
   if (value->data[0].v_pointer)
-    g_param_spec_ref (value->data[0].v_pointer);
+    g_param_spec_ref_and_context (value->data[0].v_pointer);
 }
 
 void
@@ -1108,7 +1134,7 @@ g_value_take_param (GValue     *value,
     g_return_if_fail (G_IS_PARAM_SPEC (param));
 
   if (value->data[0].v_pointer)
-    g_param_spec_unref (value->data[0].v_pointer);
+    g_param_spec_unref_and_context (value->data[0].v_pointer);
   value->data[0].v_pointer = param; /* we take over the reference count */
 }
 
Index: gobject/gparam.h
===================================================================
RCS file: /cvs/gnome/glib/gobject/gparam.h,v
retrieving revision 1.29
diff -u -p -r1.29 gparam.h
--- gobject/gparam.h	23 Nov 2005 17:54:41 -0000	1.29
+++ gobject/gparam.h	19 Jul 2006 22:37:04 -0000
@@ -211,6 +211,27 @@ GParamSpec**	g_param_spec_pool_list		(GP
 						 GType		 owner_type,
 						 guint		*n_pspecs_p);
 
+#ifdef G_OBJECT_REFDBG_ENABLED
+GParamSpec *g_param_spec_ref_with_context_glib_use_only   (GParamSpec *pspec, gpointer context);
+gpointer    g_param_spec_ref_sink_with_context_glib_use_only   (GParamSpec *pspec, gpointer context);
+void        g_param_spec_unref_with_context_glib_use_only (GParamSpec *pspec, gpointer context);
+#define g_param_spec_ref_with_context(obj, ctx) g_param_spec_ref_with_context_glib_use_only (obj, ctx)
+#define g_param_spec_ref_sink_with_context(obj, ctx) g_param_spec_ref_sink_with_context_glib_use_only (obj, ctx)
+#define g_param_spec_unref_with_context(obj, ctx) g_param_spec_unref_with_context_glib_use_only (obj, ctx)
+#else
+#define g_param_spec_ref_with_context(obj, ctx) g_param_spec_ref (obj)
+#define g_param_spec_ref_sink_with_context(obj, ctx) g_param_spec_ref_sink (obj)
+#define g_param_spec_unref_with_context(obj, ctx) g_param_spec_unref (obj)
+#endif
+
+#define g_param_spec_ref_and_context(obj) \
+	g_param_spec_ref_with_context(obj, &obj)
+#define g_param_spec_ref_sink_and_context(obj) \
+	g_param_spec_ref_sink_with_context(obj, &obj)
+#define g_param_spec_unref_and_context(obj) \
+	g_param_spec_unref_with_context(obj, &obj)
+
+
 
 
 /* contracts:
Index: gobject/gtype.c
===================================================================
RCS file: /cvs/gnome/glib/gobject/gtype.c,v
retrieving revision 1.88
diff -u -p -r1.88 gtype.c
--- gobject/gtype.c	15 Jun 2006 19:18:51 -0000	1.88
+++ gobject/gtype.c	19 Jul 2006 22:37:07 -0000
@@ -29,6 +29,13 @@
 #include	"gbsearcharray.h"
 #include	<string.h>
 
+#ifdef G_OBJECT_REFDBG_ENABLED
+#include  <refdbg.h>
+#define __RF(x) x
+#else
+#define __RF(x)
+#endif
+
 
 /* NOTE: some functions (some internal variants and exported ones)
  * invalidate data portions of the TypeNodes. if external functions/callbacks
@@ -1545,6 +1552,7 @@ g_type_create_instance (GType type)
   total_size = type_total_instance_size_I (node);
 
   instance = g_slice_alloc0 (total_size);
+  __RF (REFDBG_NEW_REF (instance, type));
 
   if (node->data->instance.private_size)
     instance_real_class_set (instance, class);
@@ -1565,7 +1573,7 @@ g_type_create_instance (GType type)
   instance->g_class = class;
   if (node->data->instance.instance_init)
     node->data->instance.instance_init (instance, class);
-  
+
   return instance;
 }
 
@@ -1598,6 +1606,7 @@ g_type_free_instance (GTypeInstance *ins
   memset (instance, 0xaa, type_total_instance_size_I (node));
 #endif
   g_slice_free1 (type_total_instance_size_I (node), instance);
+  __RF (REFDBG_DEL_REF (instance));
 
   g_type_class_unref (class);
 }
@@ -2391,7 +2400,10 @@ g_type_class_ref (GType type)
       type_class_init_Wm (node, pclass);
     }
   G_WRITE_UNLOCK (&type_rw_lock);
-  
+
+  __RF (REFDBG_NEW_TYPE (type, NODE_NAME (node),
+	node->is_instantiatable ? node->data->instance.instance_size : 0));
+
   return node->data->class.class;
 }
 
@@ -3430,7 +3442,8 @@ g_type_init_with_debug_flags (GTypeDebug
 
   /* G_TYPE_TYPE_PLUGIN
    */
-  g_type_plugin_get_type ();
+	/* prevent the compiler from optimising away ... */
+	(volatile GType)g_type_plugin_get_type ();
   
   /* G_TYPE_* value types
    */
