From 73d60cadc2f6d06f8f0cf05377524ef87853874e Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 11 Nov 2022 16:56:18 +0000 Subject: [PATCH 1/3] remove _static field --- Include/cpython/pystate.h | 3 --- Include/internal/pycore_interp.h | 3 --- Include/internal/pycore_runtime_init.h | 2 -- Python/pystate.c | 14 ++++++-------- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index 70c23427807e52..c51542bcc895cb 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 ae2a3d3b13cfa9..133088b0f36458 100644 --- a/Include/internal/pycore_interp.h +++ b/Include/internal/pycore_interp.h @@ -115,9 +115,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 3acb16b0992e92..e5ffe50d6b120c 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -47,7 +47,6 @@ extern "C" { #define _PyInterpreterState_INIT \ { \ - ._static = 1, \ .id_refcount = -1, \ DLOPENFLAGS_INIT \ .ceval = { \ @@ -67,7 +66,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 04db1fb419af62..1b8087887b9917 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -272,7 +272,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); } } @@ -356,7 +358,6 @@ PyInterpreterState_New(void) interp = &runtime->_main_interpreter; assert(interp->id == 0); assert(interp->next == NULL); - assert(interp->_static); interpreters->main = interp; } @@ -371,9 +372,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! */ @@ -759,7 +757,9 @@ alloc_threadstate(void) static void free_threadstate(PyThreadState *tstate) { - if (!tstate->_static) { + // The main thread 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); } } @@ -842,7 +842,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. @@ -856,7 +855,6 @@ new_threadstate(PyInterpreterState *interp) 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; From 2e4785741d79116aef8b0948afca8e27e495b414 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Fri, 11 Nov 2022 17:00:58 +0000 Subject: [PATCH 2/3] remove comment --- Python/pystate.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/Python/pystate.c b/Python/pystate.c index 1b8087887b9917..e2f50a2d3656d1 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -853,8 +853,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): } interp->threads.head = tstate; From 126c1962f5edf28e03baef2c53a943243004070f Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Mon, 14 Nov 2022 23:00:14 +0530 Subject: [PATCH 3/3] Update Python/pystate.c Co-authored-by: Eric Snow --- Python/pystate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pystate.c b/Python/pystate.c index e2f50a2d3656d1..a4c6e871b77dd5 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -757,7 +757,7 @@ alloc_threadstate(void) static void free_threadstate(PyThreadState *tstate) { - // The main thread of the interpreter is allocated + // 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); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy