@@ -162,16 +162,6 @@ UNSIGNAL_ASYNC_EXC(PyInterpreterState *interp)
162
162
COMPUTE_EVAL_BREAKER (interp , ceval , ceval2 );
163
163
}
164
164
165
- #ifndef NDEBUG
166
- /* Ensure that tstate is valid */
167
- static int
168
- is_tstate_valid (PyThreadState * tstate )
169
- {
170
- assert (!_PyMem_IsPtrFreed (tstate ));
171
- assert (!_PyMem_IsPtrFreed (tstate -> interp ));
172
- return 1 ;
173
- }
174
- #endif
175
165
176
166
/*
177
167
* Implementation of the Global Interpreter Lock (GIL).
@@ -324,7 +314,7 @@ drop_gil(struct _ceval_state *ceval, PyThreadState *tstate)
324
314
/* Not switched yet => wait */
325
315
if (((PyThreadState * )_Py_atomic_load_relaxed (& gil -> last_holder )) == tstate )
326
316
{
327
- assert (is_tstate_valid (tstate ));
317
+ assert (_PyThreadState_CheckConsistency (tstate ));
328
318
RESET_GIL_DROP_REQUEST (tstate -> interp );
329
319
/* NOTE: if COND_WAIT does not atomically start waiting when
330
320
releasing the mutex, another thread can run through, take
@@ -385,7 +375,7 @@ take_gil(PyThreadState *tstate)
385
375
PyThread_exit_thread ();
386
376
}
387
377
388
- assert (is_tstate_valid (tstate ));
378
+ assert (_PyThreadState_CheckConsistency (tstate ));
389
379
PyInterpreterState * interp = tstate -> interp ;
390
380
struct _ceval_state * ceval = & interp -> ceval ;
391
381
struct _gil_runtime_state * gil = ceval -> gil ;
@@ -426,7 +416,7 @@ take_gil(PyThreadState *tstate)
426
416
}
427
417
PyThread_exit_thread ();
428
418
}
429
- assert (is_tstate_valid (tstate ));
419
+ assert (_PyThreadState_CheckConsistency (tstate ));
430
420
431
421
SET_GIL_DROP_REQUEST (interp );
432
422
drop_requested = 1 ;
@@ -465,7 +455,7 @@ take_gil(PyThreadState *tstate)
465
455
drop_gil (ceval , tstate );
466
456
PyThread_exit_thread ();
467
457
}
468
- assert (is_tstate_valid (tstate ));
458
+ assert (_PyThreadState_CheckConsistency (tstate ));
469
459
470
460
if (_Py_atomic_load_relaxed (& ceval -> gil_drop_request )) {
471
461
RESET_GIL_DROP_REQUEST (interp );
@@ -673,7 +663,7 @@ PyEval_AcquireThread(PyThreadState *tstate)
673
663
void
674
664
PyEval_ReleaseThread (PyThreadState * tstate )
675
665
{
676
- assert (is_tstate_valid (tstate ));
666
+ assert (_PyThreadState_CheckConsistency (tstate ));
677
667
678
668
PyThreadState * new_tstate = _PyThreadState_SwapNoGIL (NULL );
679
669
if (new_tstate != tstate ) {
@@ -871,7 +861,7 @@ Py_AddPendingCall(int (*func)(void *), void *arg)
871
861
static int
872
862
handle_signals (PyThreadState * tstate )
873
863
{
874
- assert (is_tstate_valid (tstate ));
864
+ assert (_PyThreadState_CheckConsistency (tstate ));
875
865
if (!_Py_ThreadCanHandleSignals (tstate -> interp )) {
876
866
return 0 ;
877
867
}
977
967
_Py_FinishPendingCalls (PyThreadState * tstate )
978
968
{
979
969
assert (PyGILState_Check ());
980
- assert (is_tstate_valid (tstate ));
970
+ assert (_PyThreadState_CheckConsistency (tstate ));
981
971
982
972
if (make_pending_calls (tstate -> interp ) < 0 ) {
983
973
PyObject * exc = _PyErr_GetRaisedException (tstate );
@@ -1018,7 +1008,7 @@ Py_MakePendingCalls(void)
1018
1008
assert (PyGILState_Check ());
1019
1009
1020
1010
PyThreadState * tstate = _PyThreadState_GET ();
1021
- assert (is_tstate_valid (tstate ));
1011
+ assert (_PyThreadState_CheckConsistency (tstate ));
1022
1012
1023
1013
/* Only execute pending calls on the main thread. */
1024
1014
if (!_Py_IsMainThread () || !_Py_IsMainInterpreter (tstate -> interp )) {
0 commit comments