- automatically disable arena allocator when run under valgrind (upstream

issue 2422; patch 52)
- add patch from Josh Boyer containing diff against upstream PyBSDDB to
    make the bsddb module compile against db-4.8 (patch 53, #544275); bump
    the necessary version of db4-devel to 4.8
- patch setup.py so that it searches for db-4.8, and enable debug output
    for said search; make Setup.dist use db-4.8 (patch 54)
This commit is contained in:
dmalcolm 2009-12-18 03:20:50 +00:00
parent b56c884cb8
commit 562f19e10d
4 changed files with 3639 additions and 8 deletions

View File

@ -0,0 +1,135 @@
Index: configure.in
===================================================================
--- configure.in (revision 61828)
+++ configure.in (working copy)
@@ -2232,6 +2232,19 @@ then
fi
AC_MSG_RESULT($with_pymalloc)
+# Check for Valgrind support
+AC_MSG_CHECKING([for --with-valgrind])
+AC_ARG_WITH([valgrind],
+ AC_HELP_STRING([--with-valgrind], [Enable Valgrind support]),,
+ with_valgrind=no)
+AC_MSG_RESULT([$with_valgrind])
+if test "$with_valgrind" != no; then
+ AC_CHECK_HEADER([valgrind/valgrind.h],
+ [AC_DEFINE([WITH_VALGRIND], 1, [Define if you want pymalloc to be disabled when running under valgrind])],
+ [AC_MSG_ERROR([Valgrind support requested but headers not available])]
+ )
+fi
+
# Check for --with-wctype-functions
AC_MSG_CHECKING(for --with-wctype-functions)
AC_ARG_WITH(wctype-functions,
Index: Objects/obmalloc.c
===================================================================
--- Objects/obmalloc.c (revision 61828)
+++ Objects/obmalloc.c (working copy)
@@ -2,6 +2,21 @@
#ifdef WITH_PYMALLOC
+#ifdef WITH_VALGRIND
+#include <valgrind/valgrind.h>
+
+/* If we're using GCC, use __builtin_expect() to reduce overhead of
+ the valgrind checks */
+#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
+# define UNLIKELY(value) __builtin_expect((value), 0)
+#else
+# define UNLIKELY(value) (value)
+#endif
+
+/* -1 indicates that we haven't checked that we're running on valgrind yet. */
+static int running_on_valgrind = -1;
+#endif
+
/* An object allocator for Python.
Here is an introduction to the layers of the Python memory architecture,
@@ -726,6 +741,13 @@ PyObject_Malloc(size_t nbytes)
poolp next;
uint size;
+#ifdef WITH_VALGRIND
+ if (UNLIKELY(running_on_valgrind == -1))
+ running_on_valgrind = RUNNING_ON_VALGRIND;
+ if (UNLIKELY(running_on_valgrind))
+ goto redirect;
+#endif
+
/*
* This implicitly redirects malloc(0).
*/
@@ -916,6 +938,11 @@ PyObject_Free(void *p)
if (p == NULL) /* free(NULL) has no effect */
return;
+#ifdef WITH_VALGRIND
+ if (UNLIKELY(running_on_valgrind > 0))
+ goto redirect;
+#endif
+
pool = POOL_ADDR(p);
if (Py_ADDRESS_IN_RANGE(p, pool)) {
/* We allocated this address. */
@@ -1110,6 +1137,7 @@ PyObject_Free(void *p)
return;
}
+redirect:
/* We didn't allocate this address. */
free(p);
}
@@ -1130,6 +1158,12 @@ PyObject_Realloc(void *p, size_t nbytes)
if (p == NULL)
return PyObject_Malloc(nbytes);
+#ifdef WITH_VALGRIND
+ /* Treat running_on_valgrind == -1 the same as 0 */
+ if (UNLIKELY(running_on_valgrind > 0))
+ goto redirect;
+#endif
+
pool = POOL_ADDR(p);
if (Py_ADDRESS_IN_RANGE(p, pool)) {
/* We're in charge of this block */
@@ -1157,6 +1191,7 @@ PyObject_Realloc(void *p, size_t nbytes)
}
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
Index: Misc/NEWS
===================================================================
--- Misc/NEWS (revision 61828)
+++ Misc/NEWS (working copy)
@@ -60,6 +60,11 @@ Core and builtins
- Issue #2143: Fix embedded readline() hang on SSL socket EOF.
+- Issue #2422: When compiled with the ``--with-valgrind`` option, the
+ pymalloc allocator will be automatically disabled when running under
+ Valgrind. This gives improved memory leak detection when running
+ under Valgrind, while taking advantage of pymalloc at other times.
+
Library
-------
Index: pyconfig.h.in
===================================================================
--- pyconfig.h.in (revision 61828)
+++ pyconfig.h.in (working copy)
@@ -958,6 +958,9 @@
/* Define to profile with the Pentium timestamp counter */
#undef WITH_TSC
+/* Define if you want pymalloc to be disabled when running under valgrind */
+#undef WITH_VALGRIND
+
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX).

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
diff -up Python-2.6.4/Modules/Setup.dist.setup-db48 Python-2.6.4/Modules/Setup.dist
--- Python-2.6.4/Modules/Setup.dist.setup-db48 2009-12-17 22:05:07.000020150 -0500
+++ Python-2.6.4/Modules/Setup.dist 2009-12-17 22:05:12.545015367 -0500
@@ -411,7 +411,7 @@ gdbm gdbmmodule.c -lgdbm
#
# Edit the variables DB and DBLIBVERto point to the db top directory
# and the subdirectory of PORT where you built it.
-DBLIBVER=4.7
+DBLIBVER=4.8
DBINC=/usr/include/db4
DBLIB=/usr/lib
_bsddb _bsddb.c -I$(DBINC) -L$(DBLIB) -ldb-$(DBLIBVER)
diff -up Python-2.6.4/setup.py.setup-db48 Python-2.6.4/setup.py
--- Python-2.6.4/setup.py.setup-db48 2009-12-17 22:03:58.048015993 -0500
+++ Python-2.6.4/setup.py 2009-12-17 22:03:58.169016398 -0500
@@ -705,9 +705,9 @@ class PyBuildExt(build_ext):
# a release. Most open source OSes come with one or more
# versions of BerkeleyDB already installed.
- max_db_ver = (4, 7)
+ max_db_ver = (4, 8)
min_db_ver = (3, 3)
- db_setup_debug = False # verbose debug prints from this script?
+ db_setup_debug = True # verbose debug prints from this script?
def allow_db_ver(db_ver):
"""Returns a boolean if the given BerkeleyDB version is acceptable.

View File

@ -22,7 +22,7 @@
Summary: An interpreted, interactive, object-oriented programming language
Name: %{python}
Version: 2.6.4
Release: 3%{?dist}
Release: 4%{?dist}
License: Python
Group: Development/Languages
Provides: python-abi = %{pybasever}
@ -49,13 +49,24 @@ Patch16: python-2.6-rpath.patch
# Fix distutils to follow the Fedora/RHEL/CentOS policies of having .pyo files
Patch51: python-2.6-distutils_rpm.patch
# Automatically disable arena allocator when run under valgrind:
# From http://bugs.python.org/issue2422
# http://bugs.python.org/file9872/disable-pymalloc-on-valgrind-py26.patch
# with the "configure" part removed; appears to be identical to the version committed to 2.7
Patch52: disable-pymalloc-on-valgrind-py26.patch
# Patch generated by jwboyer@gmail.com to compile against db-4.8, using upstream
# http://www.jcea.es/programacion/pybsddb.htm
# See https://bugzilla.redhat.com/show_bug.cgi?id=544275
Patch53: python-2.6-update-bsddb3-4.8.patch
# ...and a further patch to setup.py so that it searches for 4.8:
Patch54: python-2.6.4-setup-db48.patch
# upstreamed
#Patch50: python-2.5-disable-egginfo.patch
# new db version
#Patch60: python-2.5.2-db47.patch
# lib64 patches
Patch101: python-2.3.4-lib64-regex.patch
Patch102: python-2.6-lib64.patch
@ -93,8 +104,9 @@ BuildRequires: libGL-devel tk tix gcc-c++ libX11-devel glibc-devel
BuildRequires: bzip2 tar /usr/bin/find pkgconfig tcl-devel tk-devel
BuildRequires: tix-devel bzip2-devel sqlite-devel
BuildRequires: autoconf
BuildRequires: db4-devel >= 4.7
BuildRequires: db4-devel >= 4.8
BuildRequires: libffi-devel
BuildRequires: valgrind-devel
URL: http://www.python.org/
@ -211,7 +223,6 @@ code that uses more than just unittest and/or test_support.py.
# Try not disabling egg-infos, bz#414711
#patch50 -p1 -b .egginfo
#%%patch60 -p1 -b .db47
%if "%{_lib}" == "lib64"
%patch101 -p1 -b .lib64-regex
@ -227,6 +238,9 @@ code that uses more than just unittest and/or test_support.py.
%patch16 -p1 -b .rpath
%patch51 -p1 -b .brprpm
%patch52 -p0 -b .valgrind
%patch53 -p1 -b .db48
%patch54 -p1 -b .setup-db48
%ifarch alpha ia64
# 64bit, but not lib64 arches need this too...
@ -256,9 +270,9 @@ if pkg-config openssl ; then
fi
# Force CC
export CC=gcc
# For patch 4, need to get a newer configure generated out of configure.in
# For patches 4 and 52, need to get a newer configure generated out of configure.in
autoconf
%configure --enable-ipv6 --enable-unicode=%{unicode} --enable-shared --with-system-ffi
%configure --enable-ipv6 --enable-unicode=%{unicode} --enable-shared --with-system-ffi --with-valgrind
make OPT="$CFLAGS" %{?_smp_mflags}
LD_LIBRARY_PATH=$topdir $topdir/python Tools/scripts/pathfix.py -i "%{_bindir}/env python%{pybasever}" .
@ -550,6 +564,15 @@ rm -fr $RPM_BUILD_ROOT
%{_libdir}/python%{pybasever}/lib-dynload/_testcapimodule.so
%changelog
* Wed Dec 16 2009 David Malcolm <dmalcolm@redhat.com> - 2.6.4-4
- automatically disable arena allocator when run under valgrind (upstream
issue 2422; patch 52)
- add patch from Josh Boyer containing diff against upstream PyBSDDB to make
the bsddb module compile against db-4.8 (patch 53, #544275); bump the necessary
version of db4-devel to 4.8
- patch setup.py so that it searches for db-4.8, and enable debug output for
said search; make Setup.dist use db-4.8 (patch 54)
* Thu Nov 12 2009 David Malcolm <dmalcolm@redhat.com> - 2.6.4-3
- fixup the build when __python_ver is set (Zach Sadecki; bug 533989); use
pybasever in the files section