[glib] gslice: disable by default under valgrind



commit 00fbc2f0ce2fb65da1027485707fbac59b91a1ef
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Apr 22 12:28:44 2013 -0400

    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

 glib/gslice.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
---
diff --git a/glib/gslice.c b/glib/gslice.c
index b70724d..e380b9f 100644
--- a/glib/gslice.c
+++ b/glib/gslice.c
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]