Turning off the slice allocator
- From: Matthias Clasen <matthias clasen gmail com>
- To: Federico Mena Quintero <federico ximian com>, Tim Janik <timj imendio com>
- Cc: Gtk+ Developers <gtk-devel-list gnome org>
- Subject: Turning off the slice allocator
- Date: Fri, 20 Jan 2006 15:52:16 -0500
Federico asked for this earlier, so I sat down and wrote a very
quick patch. It doesn't make everything in SliceConfig available via G_DEBUG,
just the always_malloc flag for now. Thats probably enough for most
people who want to turn off the slice allocator to debug memory overruns.
With the patch, you can do G_DEBUG=always_malloc foobar
to have foobar run without slice allocator. The patch currently
overrides a value set by g_slice_set_config().
Tim, do you think this is good enough ?
Matthias
Index: glib/gslice.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gslice.c,v
retrieving revision 1.13
diff -u -r1.13 gslice.c
--- glib/gslice.c 8 Jan 2006 23:21:01 -0000 1.13
+++ glib/gslice.c 20 Jan 2006 20:40:50 -0000
@@ -30,6 +30,7 @@
#include "gthreadinit.h"
#include "galias.h"
#include "glib.h"
+#include "gdebug.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* sysconf() */
#endif
@@ -273,6 +274,13 @@
#endif
mem_assert (sys_page_size >= 2 * LARGEALIGNMENT);
mem_assert ((sys_page_size & (sys_page_size - 1)) == 0);
+
+ if (!_g_debug_initialized)
+ _g_debug_init ();
+
+ if (_g_debug_flags & G_DEBUG_ALWAYS_MALLOC)
+ slice_config.always_malloc = TRUE;
+
allocator->config = slice_config;
allocator->min_page_size = sys_page_size;
#if HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN
Index: glib/gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gmessages.c,v
retrieving revision 1.76
diff -u -r1.76 gmessages.c
--- glib/gmessages.c 1 Dec 2005 16:34:23 -0000 1.76
+++ glib/gmessages.c 20 Jan 2006 20:40:50 -0000
@@ -1063,8 +1063,9 @@
if (val != NULL)
{
static const GDebugKey keys[] = {
- {"fatal_warnings", G_DEBUG_FATAL_WARNINGS},
- {"fatal_criticals", G_DEBUG_FATAL_CRITICALS}
+ { "fatal_warnings", G_DEBUG_FATAL_WARNINGS },
+ { "fatal_criticals", G_DEBUG_FATAL_CRITICALS },
+ { "always_malloc", G_DEBUG_ALWAYS_MALLOC }
};
_g_debug_flags = g_parse_debug_string (val, keys, G_N_ELEMENTS (keys));
Index: glib/gdebug.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gdebug.h,v
retrieving revision 1.6
diff -u -r1.6 gdebug.h
--- glib/gdebug.h 4 Nov 2005 19:05:30 -0000 1.6
+++ glib/gdebug.h 20 Jan 2006 20:40:50 -0000
@@ -31,7 +31,8 @@
typedef enum {
G_DEBUG_FATAL_WARNINGS = 1 << 0,
- G_DEBUG_FATAL_CRITICALS = 1 << 1
+ G_DEBUG_FATAL_CRITICALS = 1 << 1,
+ G_DEBUG_ALWAYS_MALLOC = 1 << 2
} GDebugFlag;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]