GH-99205: remove _static field from PyThreadState and PyInterpreterState (GH-99385)

This commit is contained in:
Kumar Aditya 2022-11-15 06:05:37 +05:30 committed by GitHub
parent e874c2f198
commit dc3e4350a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 18 deletions

View File

@ -120,9 +120,6 @@ struct _ts {
after allocation. */ after allocation. */
int _initialized; int _initialized;
/* Was this thread state statically allocated? */
int _static;
int py_recursion_remaining; int py_recursion_remaining;
int py_recursion_limit; int py_recursion_limit;

View File

@ -116,9 +116,6 @@ struct _is {
int _initialized; int _initialized;
int finalizing; int finalizing;
/* Was this interpreter statically allocated? */
bool _static;
struct _ceval_state ceval; struct _ceval_state ceval;
struct _gc_runtime_state gc; struct _gc_runtime_state gc;

View File

@ -83,7 +83,6 @@ extern "C" {
#define _PyInterpreterState_INIT \ #define _PyInterpreterState_INIT \
{ \ { \
._static = 1, \
.id_refcount = -1, \ .id_refcount = -1, \
DLOPENFLAGS_INIT \ DLOPENFLAGS_INIT \
.ceval = { \ .ceval = { \
@ -108,7 +107,6 @@ extern "C" {
#define _PyThreadState_INIT \ #define _PyThreadState_INIT \
{ \ { \
._static = 1, \
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \ .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
.context_ver = 1, \ .context_ver = 1, \
} }

View File

@ -275,7 +275,9 @@ alloc_interpreter(void)
static void static void
free_interpreter(PyInterpreterState *interp) free_interpreter(PyInterpreterState *interp)
{ {
if (!interp->_static) { // The main interpreter is statically allocated so
// should not be freed.
if (interp != &_PyRuntime._main_interpreter) {
PyMem_RawFree(interp); PyMem_RawFree(interp);
} }
} }
@ -359,7 +361,6 @@ PyInterpreterState_New(void)
interp = &runtime->_main_interpreter; interp = &runtime->_main_interpreter;
assert(interp->id == 0); assert(interp->id == 0);
assert(interp->next == NULL); assert(interp->next == NULL);
assert(interp->_static);
interpreters->main = interp; interpreters->main = interp;
} }
@ -374,9 +375,6 @@ PyInterpreterState_New(void)
// Set to _PyInterpreterState_INIT. // Set to _PyInterpreterState_INIT.
memcpy(interp, &initial._main_interpreter, memcpy(interp, &initial._main_interpreter,
sizeof(*interp)); sizeof(*interp));
// We need to adjust any fields that are different from the initial
// interpreter (as defined in _PyInterpreterState_INIT):
interp->_static = false;
if (id < 0) { if (id < 0) {
/* overflow or Py_Initialize() not called yet! */ /* overflow or Py_Initialize() not called yet! */
@ -762,7 +760,9 @@ alloc_threadstate(void)
static void static void
free_threadstate(PyThreadState *tstate) free_threadstate(PyThreadState *tstate)
{ {
if (!tstate->_static) { // The initial thread state of the interpreter is allocated
// as part of the interpreter state so should not be freed.
if (tstate != &tstate->interp->_initial_thread) {
PyMem_RawFree(tstate); PyMem_RawFree(tstate);
} }
} }
@ -845,7 +845,6 @@ new_threadstate(PyInterpreterState *interp)
assert(id == 1); assert(id == 1);
used_newtstate = 0; used_newtstate = 0;
tstate = &interp->_initial_thread; tstate = &interp->_initial_thread;
assert(tstate->_static);
} }
else { else {
// Every valid interpreter must have at least one thread. // Every valid interpreter must have at least one thread.
@ -857,9 +856,6 @@ new_threadstate(PyInterpreterState *interp)
memcpy(tstate, memcpy(tstate,
&initial._main_interpreter._initial_thread, &initial._main_interpreter._initial_thread,
sizeof(*tstate)); sizeof(*tstate));
// We need to adjust any fields that are different from the initial
// thread (as defined in _PyThreadState_INIT):
tstate->_static = false;
} }
interp->threads.head = tstate; interp->threads.head = tstate;