summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2011-02-14 09:34:29 +0000
committerJonny Lamb <jonny.lamb@collabora.co.uk>2011-02-14 09:34:29 +0000
commite2c8c159cd5cae2a944f4b79aec03b2bbc246f1d (patch)
treec77db75c2b388d97d52bd0cc84a7c8137d3054fd
parent2170d25419c7ed7119ca06ede93549d68a21f15f (diff)
util: add tp_g_ptr_array_extendptr-array-extend
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r--docs/reference/telepathy-glib-sections.txt1
-rw-r--r--telepathy-glib/util.c30
-rw-r--r--telepathy-glib/util.h2
3 files changed, 33 insertions, 0 deletions
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index b1fa09686..ea95d8e12 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -1346,6 +1346,7 @@ tp_verify_true
tp_verify_statement
tp_g_hash_table_update
tp_g_ptr_array_contains
+tp_g_ptr_array_extend
tp_g_value_slice_new
tp_g_value_slice_new_boolean
tp_g_value_slice_new_boxed
diff --git a/telepathy-glib/util.c b/telepathy-glib/util.c
index 63ac10f36..99257cede 100644
--- a/telepathy-glib/util.c
+++ b/telepathy-glib/util.c
@@ -1540,3 +1540,33 @@ _tp_create_temp_unix_socket (GSocketService *service,
return NULL;
}
#endif /* HAVE_GIO_UNIX */
+
+static void
+add_to_array (gpointer data,
+ gpointer user_data)
+{
+ g_ptr_array_add (user_data, data);
+}
+
+/**
+ * tp_g_ptr_array_extend:
+ * @one: a #GPtrArray to copy items to
+ * @two: a #GPtrArray to copy items from
+ *
+ * Copies all the items from @two to @one. Note that this only copies
+ * the pointers from @two, so any data being pointed to should be
+ * duped or referenced as appropriate.
+ *
+ * After this function has been called, it is safe to call
+ * g_ptr_array_free() on @two and also free the actual pointer array,
+ * as long as doing so does not free the data pointed to by the new
+ * items in @one.
+ *
+ * Since: 0.13.UNRELEASED
+ */
+void
+tp_g_ptr_array_extend (GPtrArray *one,
+ GPtrArray *two)
+{
+ g_ptr_array_foreach (two, add_to_array, one);
+}
diff --git a/telepathy-glib/util.h b/telepathy-glib/util.h
index 93a163f67..45688600f 100644
--- a/telepathy-glib/util.h
+++ b/telepathy-glib/util.h
@@ -145,6 +145,8 @@ gint64 tp_user_action_time_from_x11 (guint32 x11_time);
gboolean tp_user_action_time_should_present (gint64 user_action_time,
guint32 *x11_time);
+void tp_g_ptr_array_extend (GPtrArray *one, GPtrArray *two);
+
G_END_DECLS
#undef __TP_IN_UTIL_H__