bpo-35368: Add assertions in pymalloc to check GIL#10866
Conversation
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.
|
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). |
Sorry, something went wrong.
This PR adds an overhead at runtime for little benefit, so I abandon my PR. |
Sorry, something went wrong.
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