* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
- * Modified by the GLib Team and others 1997-1999. See the AUTHORS
+ * Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
g_list_push_allocator(GAllocator *allocator)
{
G_LOCK (current_allocator);
- g_list_validate_allocator ( allocator );
+ g_list_validate_allocator (allocator);
allocator->last = current_allocator;
current_allocator = allocator;
G_UNLOCK (current_allocator);
G_UNLOCK (current_allocator);
}
-GList*
-g_list_alloc (void)
+static inline GList*
+_g_list_alloc (void)
{
GList *list;
return list;
}
+GList*
+g_list_alloc (void)
+{
+ return _g_list_alloc ();
+}
+
void
g_list_free (GList *list)
{
if (list)
{
+ GList *last_node = list;
+
+#ifdef ENABLE_GC_FRIENDLY
+ while (last_node->next)
+ {
+ last_node->data = NULL;
+ last_node->prev = NULL;
+ last_node = last_node->next;
+ }
+ last_node->data = NULL
+ last_node->prev = NULL
+#else /* !ENABLE_GC_FRIENDLY */
list->data = list->next;
+#endif /* ENABLE_GC_FRIENDLY */
+
G_LOCK (current_allocator);
- list->next = current_allocator->free_lists;
+ last_node->next = current_allocator->free_lists;
current_allocator->free_lists = list;
G_UNLOCK (current_allocator);
}
}
-void
-g_list_free_1 (GList *list)
+static inline void
+_g_list_free_1 (GList *list)
{
if (list)
{
list->data = NULL;
+
+#ifdef ENABLE_GC_FRIENDLY
+ list->prev = NULL;
+#endif /* ENABLE_GC_FRIENDLY */
+
G_LOCK (current_allocator);
list->next = current_allocator->free_lists;
current_allocator->free_lists = list;
}
}
+void
+g_list_free_1 (GList *list)
+{
+ _g_list_free_1 (list);
+}
+
GList*
g_list_append (GList *list,
gpointer data)
GList *new_list;
GList *last;
- new_list = g_list_alloc ();
+ new_list = _g_list_alloc ();
new_list->data = data;
if (list)
{
GList *new_list;
- new_list = g_list_alloc ();
+ new_list = _g_list_alloc ();
new_list->data = data;
if (list)
if (!tmp_list)
return g_list_append (list, data);
- new_list = g_list_alloc ();
+ new_list = _g_list_alloc ();
new_list->data = data;
if (tmp_list->prev)
}
GList*
-g_list_remove (GList *list,
- gpointer data)
+g_list_remove (GList *list,
+ gconstpointer data)
{
GList *tmp;
if (list == tmp)
list = list->next;
- g_list_free_1 (tmp);
+ _g_list_free_1 (tmp);
break;
}
return list;
}
-GList*
-g_list_remove_link (GList *list,
- GList *link)
+static inline GList*
+_g_list_remove_link (GList *list,
+ GList *link)
{
if (link)
{
}
GList*
+g_list_remove_link (GList *list,
+ GList *link)
+{
+ return _g_list_remove_link (list, link);
+}
+
+GList*
+g_list_delete_link (GList *list,
+ GList *link)
+{
+ list = _g_list_remove_link (list, link);
+ _g_list_free_1 (link);
+
+ return list;
+}
+
+GList*
g_list_copy (GList *list)
{
GList *new_list = NULL;
{
GList *last;
- new_list = g_list_alloc ();
+ new_list = _g_list_alloc ();
new_list->data = list->data;
last = new_list;
list = list->next;
while (list)
{
- last->next = g_list_alloc ();
+ last->next = _g_list_alloc ();
last->next->prev = last;
last = last->next;
last->data = list->data;
}
GList*
-g_list_find (GList *list,
- gpointer data)
+g_list_find (GList *list,
+ gconstpointer data)
{
while (list)
{
}
GList*
-g_list_find_custom (GList *list,
- gpointer data,
- GCompareFunc func)
+g_list_find_custom (GList *list,
+ gconstpointer data,
+ GCompareFunc func)
{
g_return_val_if_fail (func != NULL, list);
}
gint
-g_list_index (GList *list,
- gpointer data)
+g_list_index (GList *list,
+ gconstpointer data)
{
gint i;
if (!list)
{
- new_list = g_list_alloc();
+ new_list = _g_list_alloc ();
new_list->data = data;
return new_list;
}
cmp = (*func) (data, tmp_list->data);
}
- new_list = g_list_alloc();
+ new_list = _g_list_alloc ();
new_list->data = data;
if ((!tmp_list->next) && (cmp > 0))