[gs-commits] rev 11830 - trunk/gs/base

robin at ghostscript.com robin at ghostscript.com
Wed Oct 20 17:00:28 UTC 2010


Author: robin
Date: 2010-10-20 17:00:27 +0000 (Wed, 20 Oct 2010)
New Revision: 11830

Added:
   trunk/gs/base/valgrind.h
Modified:
   trunk/gs/base/gsmdebug.h
Log:
Add a helpful valgrind header, and call it from gsmdebug.h.

The valgrind header here serves 2 purposes.

Firstly, it insulates us from platforms on which Valgrind does not exist -
if we build without defining ENABLE_VALGRIND then no dependency on any
valgrind headers exists. The standard Valgrind macros are all defined in
this header to do nothing, so they can safely be called in our code
without needing ugly #ifdef ENABLE_VALGRIND wrapping.

Secondly, it insulates us from changes in the valgrind/memcheck.h file -
if ENABLE_VALGRIND is defined we will use whatever version is defined by
the system. If new macros are defined by new versions of valgrind/memcheck.h
we simply need to add new 'empty' definitions to valgrind.h.

To start with, the only use of this code is to mark the contents of newly
allocated blocks as being undefined. Thanks to AlexCher for spotting a
cunning place to do this.



Modified: trunk/gs/base/gsmdebug.h
===================================================================
--- trunk/gs/base/gsmdebug.h	2010-10-20 16:59:51 UTC (rev 11829)
+++ trunk/gs/base/gsmdebug.h	2010-10-20 17:00:27 UTC (rev 11830)
@@ -18,6 +18,8 @@
 #ifndef gsmdebug_INCLUDED
 #  define gsmdebug_INCLUDED
 
+#include "valgrind.h"
+
 /* Define the fill patterns used for debugging the allocator. */
 extern const byte
        gs_alloc_fill_alloc,	/* allocated but not initialized */
@@ -35,10 +37,15 @@
 
 #ifdef DEBUG
 #  define gs_alloc_fill(ptr, fill, len)\
-     BEGIN if ( gs_alloc_debug ) gs_alloc_memset(ptr, fill, (ulong)(len)); END
+     BEGIN                                                           \
+     if ( gs_alloc_debug ) gs_alloc_memset(ptr, fill, (ulong)(len)); \
+     VALGRIND_MAKE_MEM_UNDEFINED(ptr,(ulong)(len));                  \
+     END
 #else
 #  define gs_alloc_fill(ptr, fill, len)\
-     DO_NOTHING
+     BEGIN                                                           \
+     VALGRIND_MAKE_MEM_UNDEFINED(ptr,(ulong)(len));                  \
+     END
 #endif
 
 #endif /* gsmdebug_INCLUDED */

Added: trunk/gs/base/valgrind.h
===================================================================
--- trunk/gs/base/valgrind.h	                        (rev 0)
+++ trunk/gs/base/valgrind.h	2010-10-20 17:00:27 UTC (rev 11830)
@@ -0,0 +1,77 @@
+/* Copyright (C) 2001-2007 Artifex Software, Inc.
+   All Rights Reserved.
+  
+   This software is provided AS-IS with no warranty, either express or
+   implied.
+
+   This software is distributed under license and may not be copied, modified
+   or distributed except as expressly authorized under the terms of that
+   license.  Refer to licensing information at http://www.artifex.com/
+   or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
+   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
+*/
+
+/* $Id:$ */
+/* This header provides stubbed out definitions for the valgrind/memcheck
+ * client requests that do nothing. This allows us to use these requests
+ * in the gs source without requiring that Valgrind is available on our
+ * target platform.
+ *
+ * To enable the macros, simply predefine ENABLE_VALGRIND, whereupon this
+ * file will #include "valgrind/memcheck.h" and get the real versions.
+ *
+ * This mechanism has been chosen over the more traditional "copy memcheck.h
+ * into your code" approach as not all our platforms support valgrind, and
+ * we'd rather avoid the (albeit small) overhead that the client requests
+ * cost at runtime when valgrind is not in use. Also, this protects us from
+ * changes in valgrind/memcheck.h between valgrind releases.
+ */
+
+#ifndef valgrind_INCLUDED
+#  define valgrind_INCLUDED
+
+#ifdef ENABLE_VALGRIND
+
+/* Enabled, so get the real header from the system. */
+#include "valgrind/memcheck.h"
+
+#else
+
+/* Disabled, so just stub the calls out */
+#include "stdpre.h"
+
+/* Stub out the Valgrind memcheck functions here */
+#define VALGRIND_MAKE_MEM_NOACCESS(_qzz_addr,_qzz_len)           \
+    DO_NOTHING
+#define VALGRIND_MAKE_MEM_UNDEFINED(_qzz_addr,_qzz_len)          \
+    DO_NOTHING
+#define VALGRIND_MAKE_MEM_DEFINED(_qzz_addr,_qzz_len)            \
+    DO_NOTHING
+#define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(_qzz_addr,_qzz_len)     \
+    DO_NOTHING
+#define VALGRIND_CREATE_BLOCK(_qzz_addr,_qzz_len, _qzz_desc)	   \
+    DO_NOTHING
+#define VALGRIND_DISCARD(_qzz_blkindex)                          \
+    DO_NOTHING
+#define VALGRIND_CHECK_MEM_IS_ADDRESSABLE(_qzz_addr,_qzz_len)      \
+    DO_NOTHING
+#define VALGRIND_CHECK_MEM_IS_DEFINED(_qzz_addr,_qzz_len)        \
+    DO_NOTHING
+#define VALGRIND_CHECK_VALUE_IS_DEFINED(__lvalue)                \
+    DO_NOTHING
+#define VALGRIND_DO_LEAK_CHECK                                   \
+    DO_NOTHING
+#define VALGRIND_DO_QUICK_LEAK_CHECK				 \
+    DO_NOTHING
+#define VALGRIND_COUNT_LEAKS(leaked, dubious, reachable, suppressed)     \
+    DO_NOTHING
+#define VALGRIND_COUNT_LEAK_BLOCKS(leaked, dubious, reachable, suppressed) \
+    DO_NOTHING
+#define VALGRIND_GET_VBITS(zza,zzvbits,zznbytes)                     \
+    DO_NOTHING
+#define VALGRIND_SET_VBITS(zza,zzvbits,zznbytes)                     \
+    DO_NOTHING
+
+#endif /* ENABLE_VALGRIND */
+
+#endif /* valgrind_INCLUDED */


Property changes on: trunk/gs/base/valgrind.h
___________________________________________________________________
Added: svn:executable
   + *



More information about the gs-commits mailing list