New module to parse a simple markup language
[platform/upstream/glib.git] / gmem.c
diff --git a/gmem.c b/gmem.c
index a29cb6d..bc0f923 100644 (file)
--- a/gmem.c
+++ b/gmem.c
@@ -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/. 
@@ -125,7 +125,7 @@ struct _GRealMemChunk
 
 
 static gulong g_mem_chunk_compute_size (gulong    size,
-                                       gulong    min_size);
+                                       gulong    min_size) G_GNUC_CONST;
 static gint   g_mem_chunk_area_compare (GMemArea *a,
                                        GMemArea *b);
 static gint   g_mem_chunk_area_search  (GMemArea *a,
@@ -402,11 +402,11 @@ g_free (gpointer mem)
 #ifdef ENABLE_MEM_CHECK
       t = (gulong*) ((guchar*) mem - SIZEOF_LONG);
       if (*t >= 1)
-       g_warning ("freeing previously freed memory\n");
+        g_warning ("freeing previously freed (%lu times) memory\n", *t);
       *t += 1;
       mem = t;
       
-      memset ((guchar*) mem + 8, 0, size);
+      memset ((guchar*) mem + 2 * SIZEOF_LONG, 0, size);
 #else /* ENABLE_MEM_CHECK */
       free (mem);
 #endif /* ENABLE_MEM_CHECK */
@@ -456,7 +456,7 @@ g_mem_check (gpointer mem)
   t = (gulong*) ((guchar*) mem - SIZEOF_LONG - SIZEOF_LONG);
   
   if (*t >= 1)
-    g_warning ("mem: 0x%08x has been freed %lu times\n", (gulong) mem, *t);
+    g_warning ("mem: 0x%08lx has been freed %lu times\n", (gulong) mem, *t);
 #endif /* ENABLE_MEM_CHECK */
 }
 
@@ -576,7 +576,7 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
       
       /* Determine which area this piece of memory is allocated from */
       temp_area = g_tree_search (rmem_chunk->mem_tree,
-                                (GSearchFunc) g_mem_chunk_area_search,
+                                (GCompareFunc) g_mem_chunk_area_search,
                                 mem);
       
       /* If the area has been marked, then it is being destroyed.
@@ -648,9 +648,15 @@ g_mem_chunk_alloc (GMemChunk *mem_chunk)
         }
       else
         {
+#ifdef ENABLE_GC_FRIENDLY
+         rmem_chunk->mem_area = (GMemArea*) g_malloc0 (sizeof (GMemArea) -
+                                                       MEM_AREA_SIZE +
+                                                       rmem_chunk->area_size); 
+#else /* !ENABLE_GC_FRIENDLY */
          rmem_chunk->mem_area = (GMemArea*) g_malloc (sizeof (GMemArea) -
                                                       MEM_AREA_SIZE +
                                                       rmem_chunk->area_size);
+#endif /* ENABLE_GC_FRIENDLY */
          
          rmem_chunk->num_mem_areas += 1;
          rmem_chunk->mem_area->next = rmem_chunk->mem_areas;
@@ -715,6 +721,10 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
 
   rmem_chunk = (GRealMemChunk*) mem_chunk;
   
+#ifdef ENABLE_GC_FRIENDLY
+  memset (mem, 0, rmem_chunk->atom_size);
+#endif /* ENABLE_GC_FRIENDLY */
+
   /* Don't do anything if this is an ALLOC_ONLY chunk
    */
   if (rmem_chunk->type == G_ALLOC_AND_FREE)
@@ -726,7 +736,7 @@ g_mem_chunk_free (GMemChunk *mem_chunk,
       rmem_chunk->free_atoms = free_atom;
       
       temp_area = g_tree_search (rmem_chunk->mem_tree,
-                                (GSearchFunc) g_mem_chunk_area_search,
+                                (GCompareFunc) g_mem_chunk_area_search,
                                 mem);
       
       temp_area->allocated -= 1;
@@ -765,7 +775,7 @@ g_mem_chunk_clean (GMemChunk *mem_chunk)
          mem = (gpointer) temp_free_atom;
          
          mem_area = g_tree_search (rmem_chunk->mem_tree,
-                                   (GSearchFunc) g_mem_chunk_area_search,
+                                   (GCompareFunc) g_mem_chunk_area_search,
                                    mem);
          
           /* If this mem area is marked for destruction then delete the
@@ -931,7 +941,11 @@ static gint
 g_mem_chunk_area_compare (GMemArea *a,
                          GMemArea *b)
 {
-  return (a->mem - b->mem);
+  if (a->mem > b->mem)
+    return 1;
+  else if (a->mem < b->mem)
+    return -1;
+  return 0;
 }
 
 static gint