]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-99205: remove `_static` field from `PyThreadState` and `PyInterpreterState` (GH...
authorKumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Tue, 15 Nov 2022 00:35:37 +0000 (06:05 +0530)
committerGitHub <noreply@github.com>
Tue, 15 Nov 2022 00:35:37 +0000 (16:35 -0800)
Include/cpython/pystate.h
Include/internal/pycore_interp.h
Include/internal/pycore_runtime_init.h
Python/pystate.c

index 70c23427807e52d27b5005001e8e9a9c8170ab3a..c51542bcc895cb37c07fcb1679b4188191c3962d 100644 (file)
@@ -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;
 
index 976e16a3742bda45f8c32b54db5169f6bad41ee5..7c998ac770c8b66b02e81b6f3a34523f79736384 100644 (file)
@@ -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;
 
index ea98c3784ff30047bdce0b42c4f32cca1fbf21d8..62d50631d33b07119a730e0b32da233f88686f35 100644 (file)
@@ -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, \
     }
index 5d1814f4d68beabb9b9330e38ca87f5d86a4a560..5c9e4ff85536a252d4fed7685b8f65e8169f0309 100644 (file)
@@ -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;