@@ -744,7 +744,8 @@ PyInterpreterState_New(void)
744744static void
745745interpreter_clear (PyInterpreterState * interp , PyThreadState * tstate )
746746{
747- assert (interp != NULL && tstate != NULL );
747+ assert (interp != NULL );
748+ assert (tstate != NULL );
748749 _PyRuntimeState * runtime = interp -> runtime ;
749750
750751 /* XXX Conditions we need to enforce:
@@ -754,6 +755,8 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
754755 * tstate->interp must be interp
755756 * for the main interpreter, tstate must be the main thread
756757 */
758+ // XXX Ideally, we would not rely on any thread state in this function
759+ // (and we would drop the "tstate" argument).
757760
758761 if (_PySys_Audit (tstate , "cpython.PyInterpreterState_Clear" , NULL ) < 0 ) {
759762 _PyErr_Clear (tstate );
@@ -862,6 +865,8 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
862865 _PyRuntimeState * runtime = interp -> runtime ;
863866 struct pyinterpreters * interpreters = & runtime -> interpreters ;
864867
868+ // XXX Clearing the "current" thread state should happen before
869+ // we start finalizing the interpreter (or the current thread state).
865870 PyThreadState * tcur = current_fast_get (runtime );
866871 if (tcur != NULL && interp == tcur -> interp ) {
867872 /* Unset current thread. After this, many C API calls become crashy. */
@@ -1612,8 +1617,8 @@ static inline void
16121617tstate_deactivate (PyThreadState * tstate )
16131618{
16141619 assert (tstate != NULL );
1620+ // XXX assert(tstate_is_alive(tstate));
16151621 assert (tstate_is_bound (tstate ));
1616- // XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate));
16171622 assert (tstate -> _status .active );
16181623
16191624 tstate -> _status .active = 0 ;
0 commit comments