bpo-35368: Add assertions in pymalloc to check GIL by vstinner · Pull Request #10866 · python/cpython (original) (raw)

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation2 Commits1 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

vstinner

Add "assert(PyGILState_Check());" assertion to pymalloc functions
like pymalloc_alloc() to ensure that the GIL is held.

Remove also _PyGILState_check_enabled define: use directly
_PyRuntime.gilstate.check_enabled.

Note: The debug hook already uses _PyMem_DebugCheckGIL() to check
that the GIL is held.

https://bugs.python.org/issue35368

@vstinner

Add "assert(PyGILState_Check());" assertion to pymalloc functions like pymalloc_alloc() to ensure that the GIL is held.

Remove also _PyGILState_check_enabled define: use directly _PyRuntime.gilstate.check_enabled.

Note: The debug hook already uses _PyMem_DebugCheckGIL() to check that the GIL is held.

@vstinner

This change is not really a bugfix. If Python is compiled in debug mode, debug hooks are installed by default and so _PyMem_DebugCheckGIL() is checked by each PyMem_Malloc() and PyObject_Malloc() call.

This change only impacts PYTHONMALLOC=pymalloc case on Python compiled in debug mode.

The assertion is more here as a "documentation" that pymalloc is not thread-safe (currently).

@vstinner

This change is not really a bugfix. If Python is compiled in debug mode, debug hooks are installed by default and so _PyMem_DebugCheckGIL() is checked by each PyMem_Malloc() and PyObject_Malloc() call.

This PR adds an overhead at runtime for little benefit, so I abandon my PR.