diff options
author | Victor Stinner <vstinner@python.org> | 2023-10-02 14:55:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-02 14:55:06 (GMT) |
commit | 30748d36b33fe08be98c8be4e629418584c796b0 (patch) | |
tree | 2c9ae790d0178881e9a66e7fb265a1a6443bebc2 /Python/pystate.c | |
parent | 9207c870bec173dafd3f2e6c811482c782db034f (diff) | |
download | cpython-30748d36b33fe08be98c8be4e629418584c796b0.zip cpython-30748d36b33fe08be98c8be4e629418584c796b0.tar.gz cpython-30748d36b33fe08be98c8be4e629418584c796b0.tar.bz2 |
[3.12] gh-104690: thread_run() checks for tstate dangling pointer (#109056) (#109133)
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 2ee16e3..1fe88fd 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2848,6 +2848,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 |