mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-104690: thread_run() checks for tstate dangling pointer (#109056)
thread_run() of _threadmodule.c now calls _PyThreadState_CheckConsistency() to check if tstate is a dangling pointer when Python is built in debug mode. Rename ceval_gil.c is_tstate_valid() to _PyThreadState_CheckConsistency() to reuse it in _threadmodule.c.
This commit is contained in:
parent
b0edf3b98e
commit
f63d37877a
4 changed files with 35 additions and 20 deletions
|
@ -2890,6 +2890,24 @@ _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame * frame)
|
|||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Check that a Python thread state valid. In practice, this function is used
|
||||
// on a Python debug build to check if 'tstate' is a dangling pointer, if the
|
||||
// PyThreadState memory has been freed.
|
||||
//
|
||||
// Usage:
|
||||
//
|
||||
// assert(_PyThreadState_CheckConsistency(tstate));
|
||||
int
|
||||
_PyThreadState_CheckConsistency(PyThreadState *tstate)
|
||||
{
|
||||
assert(!_PyMem_IsPtrFreed(tstate));
|
||||
assert(!_PyMem_IsPtrFreed(tstate->interp));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue