mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
Fail if PyMem_Malloc() is called without holding the GIL
Issue #26563: Debug hooks on Python memory allocators now raise a fatal error if functions of the PyMem_Malloc() family are called without holding the GIL.
This commit is contained in:
parent
013024ef67
commit
ad524375af
4 changed files with 43 additions and 11 deletions
|
@ -602,15 +602,24 @@ class PyMemDebugTests(unittest.TestCase):
|
|||
regex = regex.format(ptr=self.PTR_REGEX)
|
||||
self.assertRegex(out, regex)
|
||||
|
||||
def test_pyobject_malloc_without_gil(self):
|
||||
# Calling PyObject_Malloc() without holding the GIL must raise an
|
||||
# error in debug mode.
|
||||
code = 'import _testcapi; _testcapi.pyobject_malloc_without_gil()'
|
||||
def check_malloc_without_gil(self, code):
|
||||
out = self.check(code)
|
||||
expected = ('Fatal Python error: Python memory allocator called '
|
||||
'without holding the GIL')
|
||||
self.assertIn(expected, out)
|
||||
|
||||
def test_pymem_malloc_without_gil(self):
|
||||
# Debug hooks must raise an error if PyMem_Malloc() is called
|
||||
# without holding the GIL
|
||||
code = 'import _testcapi; _testcapi.pymem_malloc_without_gil()'
|
||||
self.check_malloc_without_gil(code)
|
||||
|
||||
def test_pyobject_malloc_without_gil(self):
|
||||
# Debug hooks must raise an error if PyObject_Malloc() is called
|
||||
# without holding the GIL
|
||||
code = 'import _testcapi; _testcapi.pyobject_malloc_without_gil()'
|
||||
self.check_malloc_without_gil(code)
|
||||
|
||||
|
||||
class PyMemMallocDebugTests(PyMemDebugTests):
|
||||
PYTHONMALLOC = 'malloc_debug'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue