Revamp to be like makefile.mingw.in, make the MSVC build actually work
[platform/upstream/glib.git] / glib / glist.c
index ca37b8d..0423212 100644 (file)
@@ -2,23 +2,23 @@
  * 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/. 
@@ -78,7 +78,7 @@ void
 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);
@@ -100,8 +100,8 @@ g_list_pop_allocator (void)
   G_UNLOCK (current_allocator);
 }
 
-GList*
-g_list_alloc (void)
+static inline GList*
+_g_list_alloc (void)
 {
   GList *list;
 
@@ -140,25 +140,50 @@ g_list_alloc (void)
   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;
@@ -166,6 +191,12 @@ g_list_free_1 (GList *list)
     }
 }
 
+void
+g_list_free_1 (GList *list)
+{
+  _g_list_free_1 (list);
+}
+
 GList*
 g_list_append (GList   *list,
               gpointer  data)
@@ -173,7 +204,7 @@ g_list_append (GList        *list,
   GList *new_list;
   GList *last;
   
-  new_list = g_list_alloc ();
+  new_list = _g_list_alloc ();
   new_list->data = data;
   
   if (list)
@@ -195,7 +226,7 @@ g_list_prepend (GList        *list,
 {
   GList *new_list;
   
-  new_list = g_list_alloc ();
+  new_list = _g_list_alloc ();
   new_list->data = data;
   
   if (list)
@@ -229,7 +260,7 @@ g_list_insert (GList        *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)
@@ -265,8 +296,8 @@ g_list_concat (GList *list1, GList *list2)
 }
 
 GList*
-g_list_remove (GList   *list,
-              gpointer  data)
+g_list_remove (GList        *list,
+              gconstpointer  data)
 {
   GList *tmp;
   
@@ -285,7 +316,7 @@ g_list_remove (GList        *list,
          if (list == tmp)
            list = list->next;
          
-         g_list_free_1 (tmp);
+         _g_list_free_1 (tmp);
          
          break;
        }
@@ -293,9 +324,9 @@ g_list_remove (GList        *list,
   return list;
 }
 
-GList*
-g_list_remove_link (GList *list,
-                   GList *link)
+static inline GList*
+_g_list_remove_link (GList *list,
+                    GList *link)
 {
   if (link)
     {
@@ -315,6 +346,23 @@ g_list_remove_link (GList *list,
 }
 
 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;
@@ -323,13 +371,13 @@ g_list_copy (GList *list)
     {
       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;
@@ -378,8 +426,8 @@ g_list_nth_data (GList     *list,
 }
 
 GList*
-g_list_find (GList    *list,
-            gpointer  data)
+g_list_find (GList         *list,
+            gconstpointer  data)
 {
   while (list)
     {
@@ -392,9 +440,9 @@ g_list_find (GList    *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);
 
@@ -428,8 +476,8 @@ g_list_position (GList *list,
 }
 
 gint
-g_list_index (GList   *list,
-             gpointer data)
+g_list_index (GList         *list,
+             gconstpointer  data)
 {
   gint i;
 
@@ -510,7 +558,7 @@ g_list_insert_sorted (GList        *list,
   
   if (!list) 
     {
-      new_list = g_list_alloc();
+      new_list = _g_list_alloc ();
       new_list->data = data;
       return new_list;
     }
@@ -523,7 +571,7 @@ g_list_insert_sorted (GList        *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))