mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-03 14:42:10 +01:00
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).
This commit is contained in:
parent
2a6f3bd69a
commit
ddfc68fc98
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 13:19:54 1999 Tim Janik <timj@gtk.org>
|
Thu Sep 16 13:19:54 1999 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
* glib.h (g_trash_stack_pop): add explicit (GTrashStack*) cast for NULL
|
||||||
|
44
glib/gmem.c
44
glib/gmem.c
@ -71,7 +71,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MAX_MEM_AREA 65536L
|
|
||||||
#define MEM_AREA_SIZE 4L
|
#define MEM_AREA_SIZE 4L
|
||||||
|
|
||||||
#if SIZEOF_VOID_P > SIZEOF_LONG
|
#if SIZEOF_VOID_P > SIZEOF_LONG
|
||||||
@ -125,7 +124,8 @@ struct _GRealMemChunk
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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,
|
static gint g_mem_chunk_area_compare (GMemArea *a,
|
||||||
GMemArea *b);
|
GMemArea *b);
|
||||||
static gint g_mem_chunk_area_search (GMemArea *a,
|
static gint g_mem_chunk_area_search (GMemArea *a,
|
||||||
@ -469,8 +469,14 @@ g_mem_chunk_new (gchar *name,
|
|||||||
GRealMemChunk *mem_chunk;
|
GRealMemChunk *mem_chunk;
|
||||||
gulong rarea_size;
|
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();
|
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 = g_new (struct _GRealMemChunk, 1);
|
||||||
mem_chunk->name = name;
|
mem_chunk->name = name;
|
||||||
mem_chunk->type = type;
|
mem_chunk->type = type;
|
||||||
@ -488,29 +494,11 @@ g_mem_chunk_new (gchar *name,
|
|||||||
|
|
||||||
if (mem_chunk->atom_size % MEM_ALIGN)
|
if (mem_chunk->atom_size % MEM_ALIGN)
|
||||||
mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
|
mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
|
||||||
|
|
||||||
mem_chunk->area_size = area_size;
|
rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
|
||||||
if (mem_chunk->area_size > MAX_MEM_AREA)
|
rarea_size = g_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
|
||||||
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);
|
|
||||||
mem_chunk->area_size = rarea_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);
|
g_mutex_lock (mem_chunks_lock);
|
||||||
mem_chunk->next = mem_chunks;
|
mem_chunk->next = mem_chunks;
|
||||||
mem_chunk->prev = NULL;
|
mem_chunk->prev = NULL;
|
||||||
@ -920,7 +908,8 @@ g_blow_chunks (void)
|
|||||||
|
|
||||||
|
|
||||||
static gulong
|
static gulong
|
||||||
g_mem_chunk_compute_size (gulong size)
|
g_mem_chunk_compute_size (gulong size,
|
||||||
|
gulong min_size)
|
||||||
{
|
{
|
||||||
gulong power_of_2;
|
gulong power_of_2;
|
||||||
gulong lower, upper;
|
gulong lower, upper;
|
||||||
@ -932,9 +921,10 @@ g_mem_chunk_compute_size (gulong size)
|
|||||||
lower = power_of_2 >> 1;
|
lower = power_of_2 >> 1;
|
||||||
upper = power_of_2;
|
upper = power_of_2;
|
||||||
|
|
||||||
if ((size - lower) < (upper - size))
|
if (size - lower < upper - size && lower >= min_size)
|
||||||
return lower;
|
return lower;
|
||||||
return upper;
|
else
|
||||||
|
return upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
44
gmem.c
44
gmem.c
@ -71,7 +71,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define MAX_MEM_AREA 65536L
|
|
||||||
#define MEM_AREA_SIZE 4L
|
#define MEM_AREA_SIZE 4L
|
||||||
|
|
||||||
#if SIZEOF_VOID_P > SIZEOF_LONG
|
#if SIZEOF_VOID_P > SIZEOF_LONG
|
||||||
@ -125,7 +124,8 @@ struct _GRealMemChunk
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
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,
|
static gint g_mem_chunk_area_compare (GMemArea *a,
|
||||||
GMemArea *b);
|
GMemArea *b);
|
||||||
static gint g_mem_chunk_area_search (GMemArea *a,
|
static gint g_mem_chunk_area_search (GMemArea *a,
|
||||||
@ -469,8 +469,14 @@ g_mem_chunk_new (gchar *name,
|
|||||||
GRealMemChunk *mem_chunk;
|
GRealMemChunk *mem_chunk;
|
||||||
gulong rarea_size;
|
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();
|
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 = g_new (struct _GRealMemChunk, 1);
|
||||||
mem_chunk->name = name;
|
mem_chunk->name = name;
|
||||||
mem_chunk->type = type;
|
mem_chunk->type = type;
|
||||||
@ -488,29 +494,11 @@ g_mem_chunk_new (gchar *name,
|
|||||||
|
|
||||||
if (mem_chunk->atom_size % MEM_ALIGN)
|
if (mem_chunk->atom_size % MEM_ALIGN)
|
||||||
mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
|
mem_chunk->atom_size += MEM_ALIGN - (mem_chunk->atom_size % MEM_ALIGN);
|
||||||
|
|
||||||
mem_chunk->area_size = area_size;
|
rarea_size = area_size + sizeof (GMemArea) - MEM_AREA_SIZE;
|
||||||
if (mem_chunk->area_size > MAX_MEM_AREA)
|
rarea_size = g_mem_chunk_compute_size (rarea_size, atom_size + sizeof (GMemArea) - MEM_AREA_SIZE);
|
||||||
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);
|
|
||||||
mem_chunk->area_size = rarea_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);
|
g_mutex_lock (mem_chunks_lock);
|
||||||
mem_chunk->next = mem_chunks;
|
mem_chunk->next = mem_chunks;
|
||||||
mem_chunk->prev = NULL;
|
mem_chunk->prev = NULL;
|
||||||
@ -920,7 +908,8 @@ g_blow_chunks (void)
|
|||||||
|
|
||||||
|
|
||||||
static gulong
|
static gulong
|
||||||
g_mem_chunk_compute_size (gulong size)
|
g_mem_chunk_compute_size (gulong size,
|
||||||
|
gulong min_size)
|
||||||
{
|
{
|
||||||
gulong power_of_2;
|
gulong power_of_2;
|
||||||
gulong lower, upper;
|
gulong lower, upper;
|
||||||
@ -932,9 +921,10 @@ g_mem_chunk_compute_size (gulong size)
|
|||||||
lower = power_of_2 >> 1;
|
lower = power_of_2 >> 1;
|
||||||
upper = power_of_2;
|
upper = power_of_2;
|
||||||
|
|
||||||
if ((size - lower) < (upper - size))
|
if (size - lower < upper - size && lower >= min_size)
|
||||||
return lower;
|
return lower;
|
||||||
return upper;
|
else
|
||||||
|
return upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
Loading…
x
Reference in New Issue
Block a user