summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-03-16 11:12:53 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-03-16 11:12:53 (GMT)
commitad524375af042a549d28ec252f3071a595b892b2 (patch)
tree8d2a755845089be4a06d2c7c185d242ff379907f /Lib
parent013024ef67b7e5989e4be03f4ff2be22aa753ae0 (diff)
downloadcpython-ad524375af042a549d28ec252f3071a595b892b2.zip
cpython-ad524375af042a549d28ec252f3071a595b892b2.tar.gz
cpython-ad524375af042a549d28ec252f3071a595b892b2.tar.bz2
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.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_capi.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index 8e6245b..8f4836a 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -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'