mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-28 02:20:04 +01:00
gslice: disable by default under valgrind
All experienced GLib hackers know that G_SLICE=always-malloc is absolutely essential when valgrinding but many users of GLib don't know about this and get hit pretty hard when valgrinding their programs. When initialising gslice, add a check to see if we are running under valgrind and disable ourselves if we are. We only do the check in the case that G_SLICE= was not specified in the environment, so setting it to an empty string will prevent this default behaviour. I considered modifying gslice to use the VALGRIND_MALLOCLIKE_BLOCK client request in all cases in order to just mark the blocks properly but these calls are not free and gslice is pretty hyper-optimised. It's easier to just disable gslice completely and this way we only have to do one check during startup. It's also theoretically possible that someone might want to use valgrind to debug gslice, in which case the extra annotations would probably cause quite a lot of difficulty. https://bugzilla.gnome.org/show_bug.cgi?id=698595
This commit is contained in:
parent
c8d56d7cf7
commit
00fbc2f0ce
@ -53,6 +53,8 @@
|
||||
#include "gthread.h"
|
||||
#include "glib_trace.h"
|
||||
|
||||
#include "valgrind.h"
|
||||
|
||||
/**
|
||||
* SECTION:memory_slices
|
||||
* @title: Memory Slices
|
||||
@ -382,6 +384,17 @@ slice_config_init (SliceConfig *config)
|
||||
if (flags & (1 << 1))
|
||||
config->debug_blocks = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* G_SLICE was not specified, so check if valgrind is running and
|
||||
* disable ourselves if it is.
|
||||
*
|
||||
* This way it's possible to force gslice to be enabled under
|
||||
* valgrind just by setting G_SLICE to the empty string.
|
||||
*/
|
||||
if (RUNNING_ON_VALGRIND)
|
||||
config->always_malloc = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user