|
| 1 | +diff -up Python-2.6.6/configure.in.disable-pymalloc-on-valgrind Python-2.6.6/configure.in |
| 2 | +--- Python-2.6.6/configure.in.disable-pymalloc-on-valgrind 2010-11-29 15:45:07.199350502 -0500 |
| 3 | ++++ Python-2.6.6/configure.in 2010-11-29 15:45:07.208351260 -0500 |
| 4 | +@@ -2538,6 +2538,19 @@ then |
| 5 | + fi |
| 6 | + AC_MSG_RESULT($with_pymalloc) |
| 7 | + |
| 8 | ++# Check for Valgrind support |
| 9 | ++AC_MSG_CHECKING([for --with-valgrind]) |
| 10 | ++AC_ARG_WITH([valgrind], |
| 11 | ++ AC_HELP_STRING([--with-valgrind], [Enable Valgrind support]),, |
| 12 | ++ with_valgrind=no) |
| 13 | ++AC_MSG_RESULT([$with_valgrind]) |
| 14 | ++if test "$with_valgrind" != no; then |
| 15 | ++ AC_CHECK_HEADER([valgrind/valgrind.h], |
| 16 | ++ [AC_DEFINE([WITH_VALGRIND], 1, [Define if you want pymalloc to be disabled when running under valgrind])], |
| 17 | ++ [AC_MSG_ERROR([Valgrind support requested but headers not available])] |
| 18 | ++ ) |
| 19 | ++fi |
| 20 | ++ |
| 21 | + # Check for --with-wctype-functions |
| 22 | + AC_MSG_CHECKING(for --with-wctype-functions) |
| 23 | + AC_ARG_WITH(wctype-functions, |
| 24 | +diff -up Python-2.6.6/Misc/NEWS.disable-pymalloc-on-valgrind Python-2.6.6/Misc/NEWS |
| 25 | +--- Python-2.6.6/Misc/NEWS.disable-pymalloc-on-valgrind 2010-08-23 19:37:56.000000000 -0400 |
| 26 | ++++ Python-2.6.6/Misc/NEWS 2010-11-29 15:45:07.209350567 -0500 |
| 27 | +@@ -21,6 +21,11 @@ What's New in Python 2.6.6 rc 2? |
| 28 | + |
| 29 | + *Release date: 2010-08-16* |
| 30 | + |
| 31 | ++- Issue #2422: When compiled with the ``--with-valgrind`` option, the |
| 32 | ++ pymalloc allocator will be automatically disabled when running under |
| 33 | ++ Valgrind. This gives improved memory leak detection when running |
| 34 | ++ under Valgrind, while taking advantage of pymalloc at other times. |
| 35 | ++ |
| 36 | + Library |
| 37 | + ------- |
| 38 | + |
| 39 | +diff -up Python-2.6.6/Objects/obmalloc.c.disable-pymalloc-on-valgrind Python-2.6.6/Objects/obmalloc.c |
| 40 | +--- Python-2.6.6/Objects/obmalloc.c.disable-pymalloc-on-valgrind 2010-05-09 11:15:40.000000000 -0400 |
| 41 | ++++ Python-2.6.6/Objects/obmalloc.c 2010-11-29 15:45:07.209350567 -0500 |
| 42 | +@@ -2,6 +2,21 @@ |
| 43 | + |
| 44 | + #ifdef WITH_PYMALLOC |
| 45 | + |
| 46 | ++#ifdef WITH_VALGRIND |
| 47 | ++#include <valgrind/valgrind.h> |
| 48 | ++ |
| 49 | ++/* If we're using GCC, use __builtin_expect() to reduce overhead of |
| 50 | ++ the valgrind checks */ |
| 51 | ++#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) |
| 52 | ++# define UNLIKELY(value) __builtin_expect((value), 0) |
| 53 | ++#else |
| 54 | ++# define UNLIKELY(value) (value) |
| 55 | ++#endif |
| 56 | ++ |
| 57 | ++/* -1 indicates that we haven't checked that we're running on valgrind yet. */ |
| 58 | ++static int running_on_valgrind = -1; |
| 59 | ++#endif |
| 60 | ++ |
| 61 | + /* An object allocator for Python. |
| 62 | + |
| 63 | + Here is an introduction to the layers of the Python memory architecture, |
| 64 | +@@ -737,6 +752,13 @@ PyObject_Malloc(size_t nbytes) |
| 65 | + if (nbytes > PY_SSIZE_T_MAX) |
| 66 | + return NULL; |
| 67 | + |
| 68 | ++#ifdef WITH_VALGRIND |
| 69 | ++ if (UNLIKELY(running_on_valgrind == -1)) |
| 70 | ++ running_on_valgrind = RUNNING_ON_VALGRIND; |
| 71 | ++ if (UNLIKELY(running_on_valgrind)) |
| 72 | ++ goto redirect; |
| 73 | ++#endif |
| 74 | ++ |
| 75 | + /* |
| 76 | + * This implicitly redirects malloc(0). |
| 77 | + */ |
| 78 | +@@ -927,6 +949,11 @@ PyObject_Free(void *p) |
| 79 | + if (p == NULL) /* free(NULL) has no effect */ |
| 80 | + return; |
| 81 | + |
| 82 | ++#ifdef WITH_VALGRIND |
| 83 | ++ if (UNLIKELY(running_on_valgrind > 0)) |
| 84 | ++ goto redirect; |
| 85 | ++#endif |
| 86 | ++ |
| 87 | + pool = POOL_ADDR(p); |
| 88 | + if (Py_ADDRESS_IN_RANGE(p, pool)) { |
| 89 | + /* We allocated this address. */ |
| 90 | +@@ -1121,6 +1148,7 @@ PyObject_Free(void *p) |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | ++redirect: |
| 95 | + /* We didn't allocate this address. */ |
| 96 | + free(p); |
| 97 | + } |
| 98 | +@@ -1150,6 +1178,12 @@ PyObject_Realloc(void *p, size_t nbytes) |
| 99 | + if (nbytes > PY_SSIZE_T_MAX) |
| 100 | + return NULL; |
| 101 | + |
| 102 | ++#ifdef WITH_VALGRIND |
| 103 | ++ /* Treat running_on_valgrind == -1 the same as 0 */ |
| 104 | ++ if (UNLIKELY(running_on_valgrind > 0)) |
| 105 | ++ goto redirect; |
| 106 | ++#endif |
| 107 | ++ |
| 108 | + pool = POOL_ADDR(p); |
| 109 | + if (Py_ADDRESS_IN_RANGE(p, pool)) { |
| 110 | + /* We're in charge of this block */ |
| 111 | +@@ -1177,6 +1211,7 @@ PyObject_Realloc(void *p, size_t nbytes) |
| 112 | + } |
| 113 | + return bp; |
| 114 | + } |
| 115 | ++redirect: |
| 116 | + /* We're not managing this block. If nbytes <= |
| 117 | + * SMALL_REQUEST_THRESHOLD, it's tempting to try to take over this |
| 118 | + * block. However, if we do, we need to copy the valid data from |
| 119 | +diff -up Python-2.6.6/pyconfig.h.in.disable-pymalloc-on-valgrind Python-2.6.6/pyconfig.h.in |
| 120 | +--- Python-2.6.6/pyconfig.h.in.disable-pymalloc-on-valgrind 2009-10-27 08:30:12.000000000 -0400 |
| 121 | ++++ Python-2.6.6/pyconfig.h.in 2010-11-29 15:45:07.209350567 -0500 |
| 122 | +@@ -1085,6 +1085,9 @@ |
| 123 | + /* Define to empty if the keyword does not work. */ |
| 124 | + #undef volatile |
| 125 | + |
| 126 | ++/* Define if you want pymalloc to be disabled when running under valgrind */ |
| 127 | ++#undef WITH_VALGRIND |
| 128 | ++ |
| 129 | + |
| 130 | + /* Define the macros needed if on a UnixWare 7.x system. */ |
| 131 | + #if defined(__USLC__) && defined(__SCO_VERSION__) |
0 commit comments