From 312f0cbb37ec073843678c6f3202b5d7021a16e7 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Tue, 26 Jul 2011 17:12:00 +0100 Subject: add easy-valgrindability to built-in python --- python/Python-2.6.1-py2422.patch | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 python/Python-2.6.1-py2422.patch (limited to 'python/Python-2.6.1-py2422.patch') diff --git a/python/Python-2.6.1-py2422.patch b/python/Python-2.6.1-py2422.patch new file mode 100644 index 000000000000..a76e26b26280 --- /dev/null +++ b/python/Python-2.6.1-py2422.patch @@ -0,0 +1,71 @@ +http://bugs.python.org/issue2422 - adaption of the patch there to honour our G_SLICE +--- misc/Python-2.6.1/Objects/obmalloc.c 2011-07-26 13:10:12.668380720 +0100 ++++ misc/build/Python-2.6.1/Objects/obmalloc.c 2011-07-26 13:17:41.951444953 +0100 +@@ -1,7 +1,18 @@ + #include "Python.h" ++#include + + #ifdef WITH_PYMALLOC + ++static int running_with_system_allocator = -1; ++ ++/* If we're using GCC, use __builtin_expect() to reduce overhead of ++ the allocator checks */ ++#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__) ++# define UNLIKELY(value) __builtin_expect((value), 0) ++#else ++# define UNLIKELY(value) (value) ++#endif ++ + /* An object allocator for Python. + + Here is an introduction to the layers of the Python memory architecture, +@@ -728,6 +739,11 @@ + poolp next; + uint size; + ++ if (UNLIKELY(running_with_system_allocator == -1)) ++ running_with_system_allocator = (getenv("G_SLICE") != NULL); ++ if (UNLIKELY(running_with_system_allocator)) ++ goto redirect; ++ + /* + * Limit ourselves to PY_SSIZE_T_MAX bytes to prevent security holes. + * Most python internals blindly use a signed Py_ssize_t to track +@@ -927,6 +943,9 @@ + if (p == NULL) /* free(NULL) has no effect */ + return; + ++ if (UNLIKELY(running_with_system_allocator > 0)) ++ goto redirect; ++ + pool = POOL_ADDR(p); + if (Py_ADDRESS_IN_RANGE(p, pool)) { + /* We allocated this address. */ +@@ -1121,6 +1140,7 @@ + return; + } + ++redirect: + /* We didn't allocate this address. */ + free(p); + } +@@ -1150,6 +1170,10 @@ + if (nbytes > PY_SSIZE_T_MAX) + return NULL; + ++ /* Treat running_with_system_allocator == -1 the same as 0 */ ++ if (UNLIKELY(running_with_system_allocator > 0)) ++ goto redirect; ++ + pool = POOL_ADDR(p); + if (Py_ADDRESS_IN_RANGE(p, pool)) { + /* We're in charge of this block */ +@@ -1177,6 +1201,7 @@ + } + return bp; + } ++redirect: + /* We're not managing this block. If nbytes <= + * SMALL_REQUEST_THRESHOLD, it's tempting to try to take over this + * block. However, if we do, we need to copy the valid data from -- cgit