[next] telepathy-glib: Make TpWeakRef use GWeakRef

Xavier Claessens xclaesse at kemper.freedesktop.org
Fri May 9 06:25:05 PDT 2014


Module: telepathy-glib
Branch: next
Commit: c426d3352fcae3cc37c6abc0e88d8cdc49043289
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=c426d3352fcae3cc37c6abc0e88d8cdc49043289

Author: Xavier Claessens <xavier.claessens at collabora.co.uk>
Date:   Wed Apr 16 20:39:45 2014 +0100

Make TpWeakRef use GWeakRef

---

 telepathy-glib/util.c |   15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 3fd63d4..a3f36d7 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -584,13 +584,13 @@ _tp_quark_array_copy (const GQuark *quarks)
  * common in practice.
  *
  * If more than one piece of auxiliary data is required, the @user_data
- * argument to the constructor can be a struct or a #GValueArray.
+ * argument to the constructor can be a struct.
  *
  * Since: 0.11.3
  */
 struct _TpWeakRef {
     /*<private>*/
-    gpointer object;
+    GWeakRef object;
     gpointer user_data;
     GDestroyNotify destroy;
 };
@@ -620,8 +620,7 @@ tp_weak_ref_new (gpointer object,
   g_return_val_if_fail (G_IS_OBJECT (object), NULL);
 
   self = g_slice_new (TpWeakRef);
-  self->object = object;
-  g_object_add_weak_pointer (self->object, &self->object);
+  g_weak_ref_init (&self->object, object);
   self->user_data = user_data;
   self->destroy = destroy;
   return self;
@@ -658,10 +657,7 @@ tp_weak_ref_get_user_data (TpWeakRef *self)
 gpointer
 tp_weak_ref_dup_object (TpWeakRef *self)
 {
-  if (self->object != NULL)
-    return g_object_ref (self->object);
-
-  return NULL;
+  return g_weak_ref_get (&self->object);
 }
 
 /**
@@ -677,8 +673,7 @@ tp_weak_ref_dup_object (TpWeakRef *self)
 void
 tp_weak_ref_destroy (TpWeakRef *self)
 {
-  if (self->object != NULL)
-    g_object_remove_weak_pointer (self->object, &self->object);
+  g_weak_ref_clear (&self->object);
 
   if (self->destroy != NULL)
     (self->destroy) (self->user_data);



More information about the telepathy-commits mailing list