@@ -272,7 +272,9 @@ alloc_interpreter(void)
272272static void
273273free_interpreter (PyInterpreterState * interp )
274274{
275- if (!interp -> _static ) {
275+ // The main interpreter is statically allocated so
276+ // should not be freed.
277+ if (interp != & _PyRuntime ._main_interpreter ) {
276278 PyMem_RawFree (interp );
277279 }
278280}
@@ -356,7 +358,6 @@ PyInterpreterState_New(void)
356358 interp = & runtime -> _main_interpreter ;
357359 assert (interp -> id == 0 );
358360 assert (interp -> next == NULL );
359- assert (interp -> _static );
360361
361362 interpreters -> main = interp ;
362363 }
@@ -371,9 +372,6 @@ PyInterpreterState_New(void)
371372 // Set to _PyInterpreterState_INIT.
372373 memcpy (interp , & initial ._main_interpreter ,
373374 sizeof (* interp ));
374- // We need to adjust any fields that are different from the initial
375- // interpreter (as defined in _PyInterpreterState_INIT):
376- interp -> _static = false;
377375
378376 if (id < 0 ) {
379377 /* overflow or Py_Initialize() not called yet! */
@@ -759,7 +757,9 @@ alloc_threadstate(void)
759757static void
760758free_threadstate (PyThreadState * tstate )
761759{
762- if (!tstate -> _static ) {
760+ // The main thread of the interpreter is allocated
761+ // as part of the interpreter state so should not be freed.
762+ if (tstate != & tstate -> interp -> _initial_thread ) {
763763 PyMem_RawFree (tstate );
764764 }
765765}
@@ -842,7 +842,6 @@ new_threadstate(PyInterpreterState *interp)
842842 assert (id == 1 );
843843 used_newtstate = 0 ;
844844 tstate = & interp -> _initial_thread ;
845- assert (tstate -> _static );
846845 }
847846 else {
848847 // Every valid interpreter must have at least one thread.
@@ -856,7 +855,6 @@ new_threadstate(PyInterpreterState *interp)
856855 sizeof (* tstate ));
857856 // We need to adjust any fields that are different from the initial
858857 // thread (as defined in _PyThreadState_INIT):
859- tstate -> _static = false;
860858 }
861859 interp -> threads .head = tstate ;
862860
0 commit comments