@@ -163,16 +163,6 @@ UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp)
163
163
COMPUTE_EVAL_BREAKER (interp , ceval , ceval2 );
164
164
}
165
165
166
- #ifndef NDEBUG
167
- /* Ensure that tstate is valid */
168
- static int
169
- is_tstate_valid (PyThreadState * tstate )
170
- {
171
- assert (!_PyMem_IsPtrFreed (tstate ));
172
- assert (!_PyMem_IsPtrFreed (tstate -> interp ));
173
- return 1 ;
174
- }
175
- #endif
176
166
177
167
/*
178
168
* Implementation of the Global Interpreter Lock (GIL).
@@ -325,7 +315,7 @@ drop_gil(struct _ceval_state *ceval, PyThreadState *tstate)
325
315
/* Not switched yet => wait */
326
316
if (((PyThreadState * )_Py_atomic_load_relaxed (& gil -> last_holder )) == tstate )
327
317
{
328
- assert (is_tstate_valid (tstate ));
318
+ assert (_PyThreadState_CheckConsistency (tstate ));
329
319
RESET_GIL_DROP_REQUEST (tstate -> interp );
330
320
/* NOTE: if COND_WAIT does not atomically start waiting when
331
321
releasing the mutex, another thread can run through, take
@@ -386,7 +376,7 @@ take_gil(PyThreadState *tstate)
386
376
PyThread_exit_thread ();
387
377
}
388
378
389
- assert (is_tstate_valid (tstate ));
379
+ assert (_PyThreadState_CheckConsistency (tstate ));
390
380
PyInterpreterState * interp = tstate -> interp ;
391
381
struct _ceval_state * ceval = & interp -> ceval ;
392
382
struct _gil_runtime_state * gil = ceval -> gil ;
@@ -427,7 +417,7 @@ take_gil(PyThreadState *tstate)
427
417
}
428
418
PyThread_exit_thread ();
429
419
}
430
- assert (is_tstate_valid (tstate ));
420
+ assert (_PyThreadState_CheckConsistency (tstate ));
431
421
432
422
SET_GIL_DROP_REQUEST (interp );
433
423
drop_requested = 1 ;
@@ -466,7 +456,7 @@ take_gil(PyThreadState *tstate)
466
456
drop_gil (ceval , tstate );
467
457
PyThread_exit_thread ();
468
458
}
469
- assert (is_tstate_valid (tstate ));
459
+ assert (_PyThreadState_CheckConsistency (tstate ));
470
460
471
461
if (_Py_atomic_load_relaxed (& ceval -> gil_drop_request )) {
472
462
RESET_GIL_DROP_REQUEST (interp );
@@ -679,7 +669,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
679
669
void
680
670
PyEval_ReleaseThread (PyThreadState * tstate )
681
671
{
682
- assert (is_tstate_valid (tstate ));
672
+ assert (_PyThreadState_CheckConsistency (tstate ));
683
673
684
674
PyThreadState * new_tstate = _PyThreadState_SwapNoGIL (NULL );
685
675
if (new_tstate != tstate ) {
@@ -877,7 +867,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
877
867
static int
878
868
handle_signals (PyThreadState * tstate )
879
869
{
880
- assert (is_tstate_valid (tstate ));
870
+ assert (_PyThreadState_CheckConsistency (tstate ));
881
871
if (!_Py_ThreadCanHandleSignals (tstate -> interp )) {
882
872
return 0 ;
883
873
}
983
973
_Py_FinishPendingCalls (PyThreadState * tstate )
984
974
{
985
975
assert (PyGILState_Check ());
986
- assert (is_tstate_valid (tstate ));
976
+ assert (_PyThreadState_CheckConsistency (tstate ));
987
977
988
978
if (make_pending_calls (tstate -> interp ) < 0 ) {
989
979
PyObject * exc = _PyErr_GetRaisedException (tstate );
@@ -1024,7 +1014,7 @@ Py_MakePendingCalls(void)
1024
1014
assert (PyGILState_Check ());
1025
1015
1026
1016
PyThreadState * tstate = _PyThreadState_GET ();
1027
- assert (is_tstate_valid (tstate ));
1017
+ assert (_PyThreadState_CheckConsistency (tstate ));
1028
1018
1029
1019
/* Only execute pending calls on the main thread. */
1030
1020
if (!_Py_IsMainThread () || !_Py_IsMainInterpreter (tstate -> interp )) {
0 commit comments