Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 610816 - dev-lang/python: add valgrind use flag
Summary: dev-lang/python: add valgrind use flag
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Python Gentoo Team
URL:
Whiteboard:
Keywords: PullRequest
Depends on:
Blocks:
 
Reported: 2017-02-24 16:12 UTC by Jonas Jelten
Modified: 2022-11-23 06:53 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonas Jelten 2017-02-24 16:12:30 UTC
Python has valgrind support with --with-valgrind, please add a use flag for it (and depend on valgrind if it is active).
Comment 1 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2017-02-24 17:19:20 UTC
What does this option do?
Comment 2 Jonas Jelten 2017-02-24 18:59:11 UTC
https://github.com/python/cpython/blob/master/Misc/README.valgrind

The valgrind option explicitly redirects memory allocations to valgrind:

https://github.com/python/cpython/blob/5d4b09c106e2e3b7d17dd1b904568eb2ff7353d3/Objects/obmalloc.c#L1233

Which is very handy to debug issues that come up with manual python api work in c extensions or cython.
Comment 3 Jonas Jelten 2020-12-13 15:45:22 UTC
I've updated the pull request for the current python 3.9 ebuild. If it looks alright, I can add it for all currently active versions.
Comment 4 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2021-03-25 07:37:36 UTC
I'm not sure how to deal with this best.  I don't think USE=valgrind is correct here, as it would wrongly suggest that Python actually uses valgrind.

Maybe we could add USE=debug instead that unconditionally disables pymalloc.  I think that would be cleaner that supporting exactly one memory debugger.  WDYT?
Comment 5 Jonas Jelten 2022-07-05 14:07:56 UTC
Having a USE=valgrind flag would make sense to me - it enables valgrind support in Python (--with-valgrind as implemented 2009 in CPython: https://github.com/python/cpython/commit/05159c4a7b37403613772a0883bd927bb57e8060), so Python can detect if it's running under valgrind, and then memory allocation behaves differently. And it does use valgrind.h to invoke the test if we're running under Valgrind.

My usecase would be to use normal Python in nearly every execution, but once I want to trace down some corruption (mainly due to Cython) Python's valgrind support would activate. Unconditionally disabling pymalloc with USE=debug would not be helpful.
Comment 6 Larry the Git Cow gentoo-dev 2022-11-23 06:53:45 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=3b7ae26f65794fed2d6b90b85d6a81a96b326702

commit 3b7ae26f65794fed2d6b90b85d6a81a96b326702
Author:     Jonas Jelten <jj@sft.lol>
AuthorDate: 2022-11-22 19:11:50 +0000
Commit:     Michał Górny <mgorny@gentoo.org>
CommitDate: 2022-11-23 06:53:42 +0000

    dev-lang/python: add valgrind support
    
    When the valgrind useflag is enabled, Python performs a runtime check if
    it is run in the Valgrind VM, and adjusts its memory allocator to not
    use pymalloc. Valgrind then does a much better job in tracking the
    memory reachability.
    
    Closes: https://bugs.gentoo.org/610816
    Signed-off-by: Jonas Jelten <jj@sft.lol>
    Closes: https://github.com/gentoo/gentoo/pull/11012
    Signed-off-by: Michał Górny <mgorny@gentoo.org>

 dev-lang/python/metadata.xml                | 5 +++++
 dev-lang/python/python-2.7.18_p16.ebuild    | 6 +++++-
 dev-lang/python/python-3.10.8_p3.ebuild     | 4 +++-
 dev-lang/python/python-3.11.0_p2.ebuild     | 4 +++-
 dev-lang/python/python-3.12.0_alpha2.ebuild | 4 +++-
 dev-lang/python/python-3.8.15_p3.ebuild     | 5 ++++-
 dev-lang/python/python-3.9.15_p3.ebuild     | 4 +++-
 7 files changed, 26 insertions(+), 6 deletions(-)