@@ -272,7 +272,9 @@ alloc_interpreter(void)
272
272
static void
273
273
free_interpreter (PyInterpreterState * interp )
274
274
{
275
- if (!interp -> _static ) {
275
+ // The main interpreter is statically allocated so
276
+ // should not be freed.
277
+ if (interp != & _PyRuntime ._main_interpreter ) {
276
278
PyMem_RawFree (interp );
277
279
}
278
280
}
@@ -356,7 +358,6 @@ PyInterpreterState_New(void)
356
358
interp = & runtime -> _main_interpreter ;
357
359
assert (interp -> id == 0 );
358
360
assert (interp -> next == NULL );
359
- assert (interp -> _static );
360
361
361
362
interpreters -> main = interp ;
362
363
}
@@ -371,9 +372,6 @@ PyInterpreterState_New(void)
371
372
// Set to _PyInterpreterState_INIT.
372
373
memcpy (interp , & initial ._main_interpreter ,
373
374
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;
377
375
378
376
if (id < 0 ) {
379
377
/* overflow or Py_Initialize() not called yet! */
@@ -759,7 +757,9 @@ alloc_threadstate(void)
759
757
static void
760
758
free_threadstate (PyThreadState * tstate )
761
759
{
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 ) {
763
763
PyMem_RawFree (tstate );
764
764
}
765
765
}
@@ -842,7 +842,6 @@ new_threadstate(PyInterpreterState *interp)
842
842
assert (id == 1 );
843
843
used_newtstate = 0 ;
844
844
tstate = & interp -> _initial_thread ;
845
- assert (tstate -> _static );
846
845
}
847
846
else {
848
847
// Every valid interpreter must have at least one thread.
@@ -856,7 +855,6 @@ new_threadstate(PyInterpreterState *interp)
856
855
sizeof (* tstate ));
857
856
// We need to adjust any fields that are different from the initial
858
857
// thread (as defined in _PyThreadState_INIT):
859
- tstate -> _static = false;
860
858
}
861
859
interp -> threads .head = tstate ;
862
860
0 commit comments