@@ -744,7 +744,8 @@ PyInterpreterState_New(void)
744
744
static void
745
745
interpreter_clear (PyInterpreterState * interp , PyThreadState * tstate )
746
746
{
747
- assert (interp != NULL && tstate != NULL );
747
+ assert (interp != NULL );
748
+ assert (tstate != NULL );
748
749
_PyRuntimeState * runtime = interp -> runtime ;
749
750
750
751
/* XXX Conditions we need to enforce:
@@ -754,6 +755,8 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
754
755
* tstate->interp must be interp
755
756
* for the main interpreter, tstate must be the main thread
756
757
*/
758
+ // XXX Ideally, we would not rely on any thread state in this function
759
+ // (and we would drop the "tstate" argument).
757
760
758
761
if (_PySys_Audit (tstate , "cpython.PyInterpreterState_Clear" , NULL ) < 0 ) {
759
762
_PyErr_Clear (tstate );
@@ -862,6 +865,8 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
862
865
_PyRuntimeState * runtime = interp -> runtime ;
863
866
struct pyinterpreters * interpreters = & runtime -> interpreters ;
864
867
868
+ // XXX Clearing the "current" thread state should happen before
869
+ // we start finalizing the interpreter (or the current thread state).
865
870
PyThreadState * tcur = current_fast_get (runtime );
866
871
if (tcur != NULL && interp == tcur -> interp ) {
867
872
/* Unset current thread. After this, many C API calls become crashy. */
@@ -1612,8 +1617,8 @@ static inline void
1612
1617
tstate_deactivate (PyThreadState * tstate )
1613
1618
{
1614
1619
assert (tstate != NULL );
1620
+ // XXX assert(tstate_is_alive(tstate));
1615
1621
assert (tstate_is_bound (tstate ));
1616
- // XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate));
1617
1622
assert (tstate -> _status .active );
1618
1623
1619
1624
tstate -> _status .active = 0 ;
0 commit comments