diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-08 11:10:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-08 11:10:33 (GMT) |
commit | b55cf2c2d82d7567720df113117752841ce74606 (patch) | |
tree | 5a68b820cd77c21d9d5db9a4a1cfe49b309eccf0 /Python/pystate.c | |
parent | 9dd28d2da941160abf0b5f54b1e7e3a7ef4465fb (diff) | |
download | cpython-b55cf2c2d82d7567720df113117752841ce74606.zip cpython-b55cf2c2d82d7567720df113117752841ce74606.tar.gz cpython-b55cf2c2d82d7567720df113117752841ce74606.tar.bz2 |
[3.11] gh-104690: thread_run() checks for tstate dangling pointer (#109056) (#109134)
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.
(cherry picked from commit f63d37877ad166041489a968233b57540f8456e8)
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 dfca3f5..ec278ee 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2237,6 +2237,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 |