gh-128360: Add _Py_AssertHoldsTstate as assertion for holding a thread state (#128361)

Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
Peter Bierma 2025-01-20 06:34:35 -05:00 committed by GitHub
parent c6b570e5e3
commit 4d0a6595a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48 additions and 32 deletions

View file

@ -367,7 +367,7 @@ traceback_new(void)
traceback_t *traceback;
_Py_hashtable_entry_t *entry;
assert(PyGILState_Check());
_Py_AssertHoldsTstate();
/* get frames */
traceback = tracemalloc_traceback;
@ -749,7 +749,7 @@ static void
tracemalloc_clear_traces_unlocked(void)
{
// Clearing tracemalloc_filenames requires the GIL to call Py_DECREF()
assert(PyGILState_Check());
_Py_AssertHoldsTstate();
set_reentrant(1);
@ -1302,7 +1302,7 @@ PyTraceMalloc_Untrack(unsigned int domain, uintptr_t ptr)
void
_PyTraceMalloc_Fini(void)
{
assert(PyGILState_Check());
_Py_AssertHoldsTstate();
tracemalloc_deinit();
}
@ -1323,7 +1323,7 @@ _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
return 0;
}
assert(PyGILState_Check());
_Py_AssertHoldsTstate();
TABLES_LOCK();
if (!tracemalloc_config.tracing) {