@@ -216,20 +216,6 @@ _PyEvalFrameClearAndPop(PyThreadState *tstate, _PyInterpreterFrame *frame);
216
216
"cannot access free variable '%s' where it is not associated with a" \
217
217
" value in enclosing scope"
218
218
219
- #ifndef NDEBUG
220
- /* Ensure that tstate is valid: sanity check for PyEval_AcquireThread() and
221
- PyEval_RestoreThread(). Detect if tstate memory was freed. It can happen
222
- when a thread continues to run after Python finalization, especially
223
- daemon threads. */
224
- static int
225
- is_tstate_valid (PyThreadState * tstate )
226
- {
227
- assert (!_PyMem_IsPtrFreed (tstate ));
228
- assert (!_PyMem_IsPtrFreed (tstate -> interp ));
229
- return 1 ;
230
- }
231
- #endif
232
-
233
219
234
220
/* This can set eval_breaker to 0 even though gil_drop_request became
235
221
1. We believe this is all right because the eval loop will release
@@ -464,7 +450,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
464
450
void
465
451
PyEval_ReleaseThread (PyThreadState * tstate )
466
452
{
467
- assert (is_tstate_valid (tstate ));
453
+ assert (_PyThreadState_CheckConsistency (tstate ));
468
454
469
455
_PyRuntimeState * runtime = tstate -> interp -> runtime ;
470
456
PyThreadState * new_tstate = _PyThreadState_Swap (& runtime -> gilstate , NULL );
@@ -671,7 +657,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
671
657
static int
672
658
handle_signals (PyThreadState * tstate )
673
659
{
674
- assert (is_tstate_valid (tstate ));
660
+ assert (_PyThreadState_CheckConsistency (tstate ));
675
661
if (!_Py_ThreadCanHandleSignals (tstate -> interp )) {
676
662
return 0 ;
677
663
}
739
725
_Py_FinishPendingCalls (PyThreadState * tstate )
740
726
{
741
727
assert (PyGILState_Check ());
742
- assert (is_tstate_valid (tstate ));
728
+ assert (_PyThreadState_CheckConsistency (tstate ));
743
729
744
730
struct _pending_calls * pending = & tstate -> interp -> ceval .pending ;
745
731
@@ -764,7 +750,7 @@ Py_MakePendingCalls(void)
764
750
assert (PyGILState_Check ());
765
751
766
752
PyThreadState * tstate = _PyThreadState_GET ();
767
- assert (is_tstate_valid (tstate ));
753
+ assert (_PyThreadState_CheckConsistency (tstate ));
768
754
769
755
/* Python signal handler doesn't really queue a callback: it only signals
770
756
that a signal was received, see _PyEval_SignalReceived(). */
@@ -6947,7 +6933,7 @@ maybe_call_line_trace(Py_tracefunc func, PyObject *obj,
6947
6933
int
6948
6934
_PyEval_SetProfile (PyThreadState * tstate , Py_tracefunc func , PyObject * arg )
6949
6935
{
6950
- assert (is_tstate_valid (tstate ));
6936
+ assert (_PyThreadState_CheckConsistency (tstate ));
6951
6937
/* The caller must hold the GIL */
6952
6938
assert (PyGILState_Check ());
6953
6939
@@ -6999,7 +6985,7 @@ PyEval_SetProfile(Py_tracefunc func, PyObject *arg)
6999
6985
int
7000
6986
_PyEval_SetTrace (PyThreadState * tstate , Py_tracefunc func , PyObject * arg )
7001
6987
{
7002
- assert (is_tstate_valid (tstate ));
6988
+ assert (_PyThreadState_CheckConsistency (tstate ));
7003
6989
/* The caller must hold the GIL */
7004
6990
assert (PyGILState_Check ());
7005
6991
0 commit comments