applied patch from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem

Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>

        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
        restriction of 65536 bytes. we also catch cases where users pass an area
        size < atom size with a return_if_fail statement now (which is ok,
        because previously this lead to memory corruption anyways).
diff --git a/ChangeLog b/ChangeLog
index 381e68f..0eba0ed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-12
+++ b/ChangeLog.pre-2-12
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 381e68f..0eba0ed 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,17 @@
+Fri Sep 17 10:24:45 1999  Tim Janik  <timj@gtk.org>
+
+        * gmem.c (g_mem_chunk_compute_size) (g_mem_chunk_new): applied patch
+        from Soeren Sandmann <sandmann@daimi.au.dk>, to force mem chunk's area
+        sizes to be a multitiple of atom_size, and to eliminate the MAX_MEM_AREA
+        restriction of 65536 bytes. we also catch cases where users pass an area
+        size < atom size with a return_if_fail statement now (which is ok,
+        because previously this lead to memory corruption anyways).
+
+Thu Sep 16 01:31:43 1999  Tim Janik  <timj@gtk.org>
+
+	* configure.in: version increment to GLib-1.2.5, interface age 5,
+	binary age 5.
+
 Thu Aug 26 15:09:36 1999  Tim Janik  <timj@gtk.org>
 
         * Makefile.am:
diff --git a/configure.in b/configure.in
index 1f56e01..c0071f0 100644
--- a/configure.in
+++ b/configure.in
@@ -33,9 +33,9 @@
 #
 GLIB_MAJOR_VERSION=1
 GLIB_MINOR_VERSION=2
-GLIB_MICRO_VERSION=4
-GLIB_INTERFACE_AGE=4
-GLIB_BINARY_AGE=4
+GLIB_MICRO_VERSION=5
+GLIB_INTERFACE_AGE=5
+GLIB_BINARY_AGE=5
 GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION
 dnl
 AC_DIVERT_POP()dnl
diff --git a/glib/gmem.c b/glib/gmem.c
index 88a49e1..a29cb6d 100644
--- a/glib/gmem.c
+++ b/glib/gmem.c
@@ -71,7 +71,6 @@
 #endif
 
 
-#define MAX_MEM_AREA  65536L
 #define MEM_AREA_SIZE 4L
 
 #if SIZEOF_VOID_P > SIZEOF_LONG
@@ -125,7 +124,8 @@
 };
 
 
-static gulong g_mem_chunk_compute_size (gulong    size);
+static gulong g_mem_chunk_compute_size (gulong    size,
+					gulong    min_size);
 static gint   g_mem_chunk_area_compare (GMemArea *a,
 					GMemArea *b);
 static gint   g_mem_chunk_area_search  (GMemArea *a,
@@ -469,8 +469,14 @@
   GRealMemChunk *mem_chunk;
   gulong rarea_size;
 
+  g_return_val_if_fail (atom_size > 0, NULL);
+  g_return_val_if_fail (area_size >= atom_size, NULL);
+
   ENTER_MEM_CHUNK_ROUTINE();
 
+  area_size = (area_size + atom_size - 1) / atom_size;
+  area_size *= atom_size;
+
   mem_chunk = g_new (struct _GRealMemChunk, 1);
   mem_chunk->name = name;
   mem_chunk->type = type;
@@ -488,29 +494,11 @@
   
   if (mem_chunk->atom_size % MEM_ALIGN)
     mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
-  
-  mem_chunk->area_size = area_size;
-  if (mem_chunk->area_size > MAX_MEM_AREA)
-    mem_chunk->area_size = MAX_MEM_AREA;
-  while (mem_chunk->area_size < mem_chunk->atom_size)
-    mem_chunk->area_size *= 2;
-  
-  rarea_size = mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
-  rarea_size = g_mem_chunk_compute_size (rarea_size);
+
+  rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
+  rarea_size = g_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
   mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
-  
-  /*
-    mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
-    if (mem_chunk->area_size < mem_chunk->atom_size)
-    {
-    mem_chunk->area_size = (mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE) * 2;
-    mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
-    }
-    
-    if (mem_chunk->area_size % mem_chunk->atom_size)
-    mem_chunk->area_size += mem_chunk->atom_size - (mem_chunk->area_size % mem_chunk->atom_size);
-  */
-  
+
   g_mutex_lock (mem_chunks_lock);
   mem_chunk->next = mem_chunks;
   mem_chunk->prev = NULL;
@@ -920,7 +908,8 @@
 
 
 static gulong
-g_mem_chunk_compute_size (gulong size)
+g_mem_chunk_compute_size (gulong size,
+			  gulong min_size)
 {
   gulong power_of_2;
   gulong lower, upper;
@@ -932,9 +921,10 @@
   lower = power_of_2 >> 1;
   upper = power_of_2;
   
-  if ((size - lower) < (upper - size))
+  if (size - lower < upper - size && lower >= min_size)
     return lower;
-  return upper;
+  else
+    return upper;
 }
 
 static gint
diff --git a/gmem.c b/gmem.c
index 88a49e1..a29cb6d 100644
--- a/gmem.c
+++ b/gmem.c
@@ -71,7 +71,6 @@
 #endif
 
 
-#define MAX_MEM_AREA  65536L
 #define MEM_AREA_SIZE 4L
 
 #if SIZEOF_VOID_P > SIZEOF_LONG
@@ -125,7 +124,8 @@
 };
 
 
-static gulong g_mem_chunk_compute_size (gulong    size);
+static gulong g_mem_chunk_compute_size (gulong    size,
+					gulong    min_size);
 static gint   g_mem_chunk_area_compare (GMemArea *a,
 					GMemArea *b);
 static gint   g_mem_chunk_area_search  (GMemArea *a,
@@ -469,8 +469,14 @@
   GRealMemChunk *mem_chunk;
   gulong rarea_size;
 
+  g_return_val_if_fail (atom_size > 0, NULL);
+  g_return_val_if_fail (area_size >= atom_size, NULL);
+
   ENTER_MEM_CHUNK_ROUTINE();
 
+  area_size = (area_size + atom_size - 1) / atom_size;
+  area_size *= atom_size;
+
   mem_chunk = g_new (struct _GRealMemChunk, 1);
   mem_chunk->name = name;
   mem_chunk->type = type;
@@ -488,29 +494,11 @@
   
   if (mem_chunk->atom_size % MEM_ALIGN)
     mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
-  
-  mem_chunk->area_size = area_size;
-  if (mem_chunk->area_size > MAX_MEM_AREA)
-    mem_chunk->area_size = MAX_MEM_AREA;
-  while (mem_chunk->area_size < mem_chunk->atom_size)
-    mem_chunk->area_size *= 2;
-  
-  rarea_size = mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
-  rarea_size = g_mem_chunk_compute_size (rarea_size);
+
+  rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
+  rarea_size = g_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
   mem_chunk->area_size = rarea_size - (sizeof (GMemArea) - MEM_AREA_SIZE);
-  
-  /*
-    mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
-    if (mem_chunk->area_size < mem_chunk->atom_size)
-    {
-    mem_chunk->area_size = (mem_chunk->area_size + sizeof (GMemArea) - MEM_AREA_SIZE) * 2;
-    mem_chunk->area_size -= (sizeof (GMemArea) - MEM_AREA_SIZE);
-    }
-    
-    if (mem_chunk->area_size % mem_chunk->atom_size)
-    mem_chunk->area_size += mem_chunk->atom_size - (mem_chunk->area_size % mem_chunk->atom_size);
-  */
-  
+
   g_mutex_lock (mem_chunks_lock);
   mem_chunk->next = mem_chunks;
   mem_chunk->prev = NULL;
@@ -920,7 +908,8 @@
 
 
 static gulong
-g_mem_chunk_compute_size (gulong size)
+g_mem_chunk_compute_size (gulong size,
+			  gulong min_size)
 {
   gulong power_of_2;
   gulong lower, upper;
@@ -932,9 +921,10 @@
   lower = power_of_2 >> 1;
   upper = power_of_2;
   
-  if ((size - lower) < (upper - size))
+  if (size - lower < upper - size && lower >= min_size)
     return lower;
-  return upper;
+  else
+    return upper;
 }
 
 static gint