diff options
author | Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> | 2022-11-15 00:35:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-15 00:35:37 (GMT) |
commit | dc3e4350a5580bcc956312d1b20ca877d8f63215 (patch) | |
tree | e6bad39db71859742257c1f267e3785bb7bbd110 | |
parent | e874c2f1986ee01f53a9d9bdf26fa6979d8a6d35 (diff) | |
download | cpython-dc3e4350a5580bcc956312d1b20ca877d8f63215.zip cpython-dc3e4350a5580bcc956312d1b20ca877d8f63215.tar.gz cpython-dc3e4350a5580bcc956312d1b20ca877d8f63215.tar.bz2 |
GH-99205: remove `_static` field from `PyThreadState` and `PyInterpreterState` (GH-99385)
-rw-r--r-- | Include/cpython/pystate.h | 3 | ||||
-rw-r--r-- | Include/internal/pycore_interp.h | 3 | ||||
-rw-r--r-- | Include/internal/pycore_runtime_init.h | 2 | ||||
-rw-r--r-- | Python/pystate.c | 16 |
4 files changed, 6 insertions, 18 deletions
diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 70c2342..c51542b 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -120,9 +120,6 @@ struct _ts { after allocation. */ int _initialized; - /* Was this thread state statically allocated? */ - int _static; - int py_recursion_remaining; int py_recursion_limit; diff --git a/Include/internal/pycore_interp.h b/Include/internal/pycore_interp.h index 976e16a..7c998ac 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -116,9 +116,6 @@ struct _is { int _initialized; int finalizing; - /* Was this interpreter statically allocated? */ - bool _static; - struct _ceval_state ceval; struct _gc_runtime_state gc; diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index ea98c37..62d5063 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -83,7 +83,6 @@ extern "C" { #define _PyInterpreterState_INIT \ { \ - ._static = 1, \ .id_refcount = -1, \ DLOPENFLAGS_INIT \ .ceval = { \ @@ -108,7 +107,6 @@ extern "C" { #define _PyThreadState_INIT \ { \ - ._static = 1, \ .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \ .context_ver = 1, \ } diff --git a/Python/pystate.c b/Python/pystate.c index 5d1814f..5c9e4ff 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -275,7 +275,9 @@ alloc_interpreter(void) static void 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); } } @@ -359,7 +361,6 @@ PyInterpreterState_New(void) interp = &runtime->_main_interpreter; assert(interp->id == 0); assert(interp->next == NULL); - assert(interp->_static); interpreters->main = interp; } @@ -374,9 +375,6 @@ PyInterpreterState_New(void) // Set to _PyInterpreterState_INIT. memcpy(interp, &initial._main_interpreter, 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) { /* overflow or Py_Initialize() not called yet! */ @@ -762,7 +760,9 @@ alloc_threadstate(void) static void 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); } } @@ -845,7 +845,6 @@ new_threadstate(PyInterpreterState *interp) assert(id == 1); used_newtstate = 0; tstate = &interp->_initial_thread; - assert(tstate->_static); } else { // Every valid interpreter must have at least one thread. @@ -857,9 +856,6 @@ new_threadstate(PyInterpreterState *interp) memcpy(tstate, &initial._main_interpreter._initial_thread, 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; |