From 61ec7b3505ed00ee2a3a134364618acd7aed34e0 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Mon, 5 Mar 2012 19:34:36 +0000 Subject: [PATCH 05/10] _tp_object_list_copy, _tp_object_list_free: add Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46358 Signed-off-by: Simon McVittie --- telepathy-glib/base-call-content.c | 11 +++-------- telepathy-glib/base-media-call-stream.c | 9 ++------- telepathy-glib/util-internal.h | 3 +++ telepathy-glib/util.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/telepathy-glib/base-call-content.c b/telepathy-glib/base-call-content.c index ad135c7..ee16e49 100644 --- a/telepathy-glib/base-call-content.c +++ b/telepathy-glib/base-call-content.c @@ -139,6 +139,7 @@ #include "telepathy-glib/svc-call.h" #include "telepathy-glib/svc-generic.h" #include "telepathy-glib/util.h" +#include "telepathy-glib/util-internal.h" static void call_content_iface_init (gpointer g_iface, gpointer iface_data); static void call_content_dtmf_iface_init (gpointer g_iface, @@ -216,12 +217,6 @@ tp_base_call_content_constructed (GObject *obj) } static void -stream_list_destroy (GList *streams) -{ - g_list_free_full (streams, g_object_unref); -} - -static void tp_base_call_content_deinit_real (TpBaseCallContent *self) { TpDBusDaemon *bus = tp_base_connection_get_dbus_daemon ( @@ -229,7 +224,7 @@ tp_base_call_content_deinit_real (TpBaseCallContent *self) tp_dbus_daemon_unregister_object (bus, G_OBJECT (self)); - tp_clear_pointer (&self->priv->streams, stream_list_destroy); + tp_clear_pointer (&self->priv->streams, _tp_object_list_free); } static GPtrArray * @@ -248,7 +243,7 @@ tp_base_call_content_dispose (GObject *object) g_assert (self->priv->deinit_has_run); - tp_clear_pointer (&self->priv->streams, stream_list_destroy); + tp_clear_pointer (&self->priv->streams, _tp_object_list_free); g_object_notify (G_OBJECT (self), "streams"); tp_clear_object (&self->priv->conn); diff --git a/telepathy-glib/base-media-call-stream.c b/telepathy-glib/base-media-call-stream.c index 0b1dda8..b48c9a7 100644 --- a/telepathy-glib/base-media-call-stream.c +++ b/telepathy-glib/base-media-call-stream.c @@ -161,6 +161,7 @@ #include "telepathy-glib/svc-properties-interface.h" #include "telepathy-glib/svc-call.h" #include "telepathy-glib/util.h" +#include "telepathy-glib/util-internal.h" static void call_stream_media_iface_init (gpointer, gpointer); @@ -242,17 +243,11 @@ tp_base_media_call_stream_init (TpBaseMediaCallStream *self) } static void -endpoints_list_destroy (GList *endpoints) -{ - g_list_free_full (endpoints, g_object_unref); -} - -static void tp_base_media_call_stream_dispose (GObject *object) { TpBaseMediaCallStream *self = TP_BASE_MEDIA_CALL_STREAM (object); - tp_clear_pointer (&self->priv->endpoints, endpoints_list_destroy); + tp_clear_pointer (&self->priv->endpoints, _tp_object_list_free); if (G_OBJECT_CLASS (tp_base_media_call_stream_parent_class)->dispose) G_OBJECT_CLASS (tp_base_media_call_stream_parent_class)->dispose (object); diff --git a/telepathy-glib/util-internal.h b/telepathy-glib/util-internal.h index 0b15b60..a7937ba 100644 --- a/telepathy-glib/util-internal.h +++ b/telepathy-glib/util-internal.h @@ -105,4 +105,7 @@ gboolean _tp_contacts_to_handles (TpConnection *connection, GPtrArray *_tp_contacts_from_values (GHashTable *table); +GList *_tp_object_list_copy (GList *l); +void _tp_object_list_free (GList *l); + #endif /* __TP_UTIL_INTERNAL_H__ */ diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c index 7a46f50..a346d34 100644 --- a/telepathy-glib/util.c +++ b/telepathy-glib/util.c @@ -2039,3 +2039,33 @@ _tp_contacts_from_values (GHashTable *table) return contacts; } + +/* + * @l: (transfer none) (element-type GLib.Object): a list of #GObject or + * any subclass + * + * Returns: (transfer full): a copy of @l + */ +GList * +_tp_object_list_copy (GList *l) +{ + GList *new_l; + + new_l = g_list_copy (l); + g_list_foreach (new_l, (GFunc) g_object_ref, NULL); + return new_l; +} + +/* + * @l: (transfer full) (element-type GLib.Object): a list of #GObject or + * any subclass + * + * Unref each item of @l and free the list. + * + * This function can be cast to #GDestroyNotify. + */ +void +_tp_object_list_free (GList *l) +{ + g_list_free_full (l, g_object_unref); +} -- 1.7.9.1