summaryrefslogtreecommitdiff
path: root/glib
diff options
context:
space:
mode:
authorTim Janik <timj@src.gnome.org>1998-06-08 04:09:21 +0000
committerTim Janik <timj@src.gnome.org>1998-06-08 04:09:21 +0000
commit257c54a0210d75fd17d19d555a90c52a07693ef4 (patch)
treeac2dcb82a43bf0d6171ec0094a3e50bd3c831fc1 /glib
parent207eecc4240b2b296ad2f88c6377d19765135b84 (diff)
downloadgdk-pixbuf-257c54a0210d75fd17d19d555a90c52a07693ef4.tar.gz
check for func in g_[s]list_insert_sorted and g_[s]list_find_custom
Diffstat (limited to 'glib')
-rw-r--r--glib/glib.h166
-rw-r--r--glib/glist.c19
-rw-r--r--glib/gslist.c19
3 files changed, 106 insertions, 98 deletions
diff --git a/glib/glib.h b/glib/glib.h
index 8fe9536be..693a0cccf 100644
--- a/glib/glib.h
+++ b/glib/glib.h
@@ -523,93 +523,91 @@ typedef enum
/* Doubly linked lists
*/
-GList* g_list_alloc (void);
-void g_list_free (GList *list);
-void g_list_free_1 (GList *list);
-GList* g_list_append (GList *list,
- gpointer data);
-GList* g_list_prepend (GList *list,
- gpointer data);
-GList* g_list_insert (GList *list,
- gpointer data,
- gint position);
-GList* g_list_insert_sorted
- (GList *list,
- gpointer data,
- GCompareFunc func);
-GList* g_list_concat (GList *list1,
- GList *list2);
-GList* g_list_remove (GList *list,
- gpointer data);
-GList* g_list_remove_link (GList *list,
- GList *link);
-GList* g_list_reverse (GList *list);
-GList* g_list_nth (GList *list,
- guint n);
-GList* g_list_find (GList *list,
- gpointer data);
-GList *g_list_find_custom (GList *list,
- gpointer data,
- GCompareFunc func);
-gint g_list_position (GList *list,
- GList *link);
-gint g_list_index (GList *list,
- gpointer data);
-GList* g_list_last (GList *list);
-GList* g_list_first (GList *list);
-guint g_list_length (GList *list);
-void g_list_foreach (GList *list,
- GFunc func,
- gpointer user_data);
-gpointer g_list_nth_data (GList *list,
- guint n);
-
-#define g_list_previous(list) ((list) ? (((GList *)list)->prev) : NULL)
-#define g_list_next(list) ((list) ? (((GList *)list)->next) : NULL)
+GList* g_list_alloc (void);
+void g_list_free (GList *list);
+void g_list_free_1 (GList *list);
+GList* g_list_append (GList *list,
+ gpointer data);
+GList* g_list_prepend (GList *list,
+ gpointer data);
+GList* g_list_insert (GList *list,
+ gpointer data,
+ gint position);
+GList* g_list_insert_sorted (GList *list,
+ gpointer data,
+ GCompareFunc func);
+GList* g_list_concat (GList *list1,
+ GList *list2);
+GList* g_list_remove (GList *list,
+ gpointer data);
+GList* g_list_remove_link (GList *list,
+ GList *link);
+GList* g_list_reverse (GList *list);
+GList* g_list_nth (GList *list,
+ guint n);
+GList* g_list_find (GList *list,
+ gpointer data);
+GList* g_list_find_custom (GList *list,
+ gpointer data,
+ GCompareFunc func);
+gint g_list_position (GList *list,
+ GList *link);
+gint g_list_index (GList *list,
+ gpointer data);
+GList* g_list_last (GList *list);
+GList* g_list_first (GList *list);
+guint g_list_length (GList *list);
+void g_list_foreach (GList *list,
+ GFunc func,
+ gpointer user_data);
+gpointer g_list_nth_data (GList *list,
+ guint n);
+
+#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
+#define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
/* Singly linked lists
*/
-GSList* g_slist_alloc (void);
-void g_slist_free (GSList *list);
-void g_slist_free_1 (GSList *list);
-GSList* g_slist_append (GSList *list,
- gpointer data);
-GSList* g_slist_prepend (GSList *list,
- gpointer data);
-GSList* g_slist_insert (GSList *list,
- gpointer data,
- gint position);
-GSList* g_slist_insert_sorted
- (GSList *list,
- gpointer data,
- GCompareFunc func);
-GSList* g_slist_concat (GSList *list1,
- GSList *list2);
-GSList* g_slist_remove (GSList *list,
- gpointer data);
-GSList* g_slist_remove_link (GSList *list,
- GSList *link);
-GSList* g_slist_reverse (GSList *list);
-GSList* g_slist_nth (GSList *list,
- guint n);
-GSList* g_slist_find (GSList *list,
- gpointer data);
-GSList *g_slist_find_custom (GSList *list,
- gpointer data,
- GCompareFunc func);
-gint g_slist_position (GSList *list,
- GSList *link);
-gint g_slist_index (GSList *list,
- gpointer data);
-GSList* g_slist_last (GSList *list);
-guint g_slist_length (GSList *list);
-void g_slist_foreach (GSList *list,
- GFunc func,
- gpointer user_data);
-gpointer g_slist_nth_data (GSList *list,
- guint n);
-
-#define g_slist_next(list) ((list) ? (((GSList *)list)->next) : NULL)
+GSList* g_slist_alloc (void);
+void g_slist_free (GSList *list);
+void g_slist_free_1 (GSList *list);
+GSList* g_slist_append (GSList *list,
+ gpointer data);
+GSList* g_slist_prepend (GSList *list,
+ gpointer data);
+GSList* g_slist_insert (GSList *list,
+ gpointer data,
+ gint position);
+GSList* g_slist_insert_sorted (GSList *list,
+ gpointer data,
+ GCompareFunc func);
+GSList* g_slist_concat (GSList *list1,
+ GSList *list2);
+GSList* g_slist_remove (GSList *list,
+ gpointer data);
+GSList* g_slist_remove_link (GSList *list,
+ GSList *link);
+GSList* g_slist_reverse (GSList *list);
+GSList* g_slist_nth (GSList *list,
+ guint n);
+GSList* g_slist_find (GSList *list,
+ gpointer data);
+GSList* g_slist_find_custom (GSList *list,
+ gpointer data,
+ GCompareFunc func);
+gint g_slist_position (GSList *list,
+ GSList *link);
+gint g_slist_index (GSList *list,
+ gpointer data);
+GSList* g_slist_last (GSList *list);
+guint g_slist_length (GSList *list);
+void g_slist_foreach (GSList *list,
+ GFunc func,
+ gpointer user_data);
+gpointer g_slist_nth_data (GSList *list,
+ guint n);
+
+#define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
/* List Allocators
*/
diff --git a/glib/glist.c b/glib/glist.c
index 3f84528aa..dc211580a 100644
--- a/glib/glist.c
+++ b/glib/glist.c
@@ -324,18 +324,21 @@ g_list_find (GList *list,
return list;
}
-GList *
-g_list_find_custom(GList *list, gpointer data, GCompareFunc func)
+GList*
+g_list_find_custom (GList *list,
+ gpointer data,
+ GCompareFunc func)
{
- if(!func) return g_list_find(list, data);
+ g_return_val_if_fail (func != NULL, list);
while (list)
{
- if ( !((*func)(list->data, data)) ) break;
+ if (! func (list->data, data))
+ return list;
list = list->next;
}
- return list;
+ return NULL;
}
@@ -428,13 +431,15 @@ g_list_foreach (GList *list,
GList*
-g_list_insert_sorted (GList *list,
- gpointer data,
+g_list_insert_sorted (GList *list,
+ gpointer data,
GCompareFunc func)
{
GList *tmp_list = list;
GList *new_list;
gint cmp;
+
+ g_return_val_if_fail (func != NULL, list);
if (!list)
{
diff --git a/glib/gslist.c b/glib/gslist.c
index cdfc64cb3..3a201b41b 100644
--- a/glib/gslist.c
+++ b/glib/gslist.c
@@ -313,18 +313,21 @@ g_slist_find (GSList *list,
return list;
}
-GSList *
-g_slist_find_custom(GSList *list, gpointer data, GCompareFunc func)
+GSList*
+g_slist_find_custom (GSList *list,
+ gpointer data,
+ GCompareFunc func)
{
- if(!func) return g_slist_find(list, data);
+ g_return_val_if_fail (func != NULL, list);
while (list)
{
- if ( !((*func)(list->data, data)) ) break;
+ if (! func (list->data, data))
+ return list;
list = list->next;
}
- return list;
+ return NULL;
}
gint
@@ -403,8 +406,8 @@ g_slist_foreach (GSList *list,
}
GSList*
-g_slist_insert_sorted (GSList *list,
- gpointer data,
+g_slist_insert_sorted (GSList *list,
+ gpointer data,
GCompareFunc func)
{
GSList *tmp_list = list;
@@ -412,6 +415,8 @@ g_slist_insert_sorted (GSList *list,
GSList *new_list;
gint cmp;
+ g_return_val_if_fail (func != NULL, list);
+
if (!list)
{
new_list = g_slist_alloc();