[glib] Have g_queue_remove() return a boolean
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Have g_queue_remove() return a boolean
- Date: Sat, 4 Jun 2011 02:04:49 +0000 (UTC)
commit f065d7d60e2b6110705b1b32f050ccad0bcde62f
Author: Matthew Barnes <mbarnes redhat com>
Date: Sat Oct 16 07:40:44 2010 -0400
Have g_queue_remove() return a boolean
g_queue_remove() should return a boolean so callers can verify that an
element was found and removed, as in the following example:
if (g_queue_remove (queue, referenced_object))
g_object_unref (referenced_object);
Similarly, g_queue_remove_all() should return the number of elements
found and removed.
https://bugzilla.gnome.org/show_bug.cgi?id=632294
glib/gqueue.c | 19 +++++++++++++++----
glib/gqueue.h | 4 ++--
2 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/glib/gqueue.c b/glib/gqueue.c
index 2e7d05a..358b669 100644
--- a/glib/gqueue.c
+++ b/glib/gqueue.c
@@ -880,20 +880,24 @@ g_queue_index (GQueue *queue,
*
* Removes the first element in @queue that contains @data.
*
+ * Return value: %TRUE if @data was found and removed from @queue
+ *
* Since: 2.4
**/
-void
+gboolean
g_queue_remove (GQueue *queue,
gconstpointer data)
{
GList *link;
- g_return_if_fail (queue != NULL);
+ g_return_val_if_fail (queue != NULL, FALSE);
link = g_list_find (queue->head, data);
if (link)
g_queue_delete_link (queue, link);
+
+ return (link != NULL);
}
/**
@@ -903,15 +907,20 @@ g_queue_remove (GQueue *queue,
*
* Remove all elements whose data equals @data from @queue.
*
+ * Return value: the number of elements removed from @queue
+ *
* Since: 2.4
**/
-void
+guint
g_queue_remove_all (GQueue *queue,
gconstpointer data)
{
GList *list;
+ guint old_length;
- g_return_if_fail (queue != NULL);
+ g_return_val_if_fail (queue != NULL, 0);
+
+ old_length = queue->length;
list = queue->head;
while (list)
@@ -923,6 +932,8 @@ g_queue_remove_all (GQueue *queue,
list = next;
}
+
+ return (old_length - queue->length);
}
/**
diff --git a/glib/gqueue.h b/glib/gqueue.h
index e78488f..345d2c7 100644
--- a/glib/gqueue.h
+++ b/glib/gqueue.h
@@ -85,9 +85,9 @@ gpointer g_queue_peek_nth (GQueue *queue,
guint n);
gint g_queue_index (GQueue *queue,
gconstpointer data);
-void g_queue_remove (GQueue *queue,
+gboolean g_queue_remove (GQueue *queue,
gconstpointer data);
-void g_queue_remove_all (GQueue *queue,
+guint g_queue_remove_all (GQueue *queue,
gconstpointer data);
void g_queue_insert_before (GQueue *queue,
GList *sibling,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]