diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-08 09:50:46 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 09:50:46 (GMT) |
commit | f63d37877ad166041489a968233b57540f8456e8 (patch) | |
tree | d4c6bb8c8478a3d0e3760b11e7e24a143012ba6e /Python/pystate.c | |
parent | b0edf3b98e4b3e68a13776e034b9dd86ad7e529d (diff) | |
download | cpython-f63d37877ad166041489a968233b57540f8456e8.zip cpython-f63d37877ad166041489a968233b57540f8456e8.tar.gz cpython-f63d37877ad166041489a968233b57540f8456e8.tar.bz2 |
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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 89275fd..09c3538 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -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 |