@@ -275,7 +275,9 @@ alloc_interpreter(void)
275
275
static void
276
276
free_interpreter (PyInterpreterState * interp )
277
277
{
278
- if (!interp -> _static ) {
278
+ // The main interpreter is statically allocated so
279
+ // should not be freed.
280
+ if (interp != & _PyRuntime ._main_interpreter ) {
279
281
PyMem_RawFree (interp );
280
282
}
281
283
}
@@ -359,7 +361,6 @@ PyInterpreterState_New(void)
359
361
interp = & runtime -> _main_interpreter ;
360
362
assert (interp -> id == 0 );
361
363
assert (interp -> next == NULL );
362
- assert (interp -> _static );
363
364
364
365
interpreters -> main = interp ;
365
366
}
@@ -374,9 +375,6 @@ PyInterpreterState_New(void)
374
375
// Set to _PyInterpreterState_INIT.
375
376
memcpy (interp , & initial ._main_interpreter ,
376
377
sizeof (* interp ));
377
- // We need to adjust any fields that are different from the initial
378
- // interpreter (as defined in _PyInterpreterState_INIT):
379
- interp -> _static = false;
380
378
381
379
if (id < 0 ) {
382
380
/* overflow or Py_Initialize() not called yet! */
@@ -762,7 +760,9 @@ alloc_threadstate(void)
762
760
static void
763
761
free_threadstate (PyThreadState * tstate )
764
762
{
765
- if (!tstate -> _static ) {
763
+ // The initial thread state of the interpreter is allocated
764
+ // as part of the interpreter state so should not be freed.
765
+ if (tstate != & tstate -> interp -> _initial_thread ) {
766
766
PyMem_RawFree (tstate );
767
767
}
768
768
}
@@ -845,7 +845,6 @@ new_threadstate(PyInterpreterState *interp)
845
845
assert (id == 1 );
846
846
used_newtstate = 0 ;
847
847
tstate = & interp -> _initial_thread ;
848
- assert (tstate -> _static );
849
848
}
850
849
else {
851
850
// Every valid interpreter must have at least one thread.
@@ -857,9 +856,6 @@ new_threadstate(PyInterpreterState *interp)
857
856
memcpy (tstate ,
858
857
& initial ._main_interpreter ._initial_thread ,
859
858
sizeof (* tstate ));
860
- // We need to adjust any fields that are different from the initial
861
- // thread (as defined in _PyThreadState_INIT):
862
- tstate -> _static = false;
863
859
}
864
860
interp -> threads .head = tstate ;
865
861
0 commit comments