From c40f16215d9ec965729b5ba71f7da1c3f3dfe19e Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 11 Oct 2023 06:05:43 -0600 Subject: [PATCH] Drop PyThreadState.whence. --- Include/cpython/pystate.h | 9 --------- Include/internal/pycore_pystate.h | 4 +--- Include/internal/pycore_runtime_init.h | 1 - Modules/_threadmodule.c | 2 +- Modules/_xxsubinterpretersmodule.c | 2 -- Python/pylifecycle.c | 6 ++---- Python/pystate.c | 26 +++++++++----------------- 7 files changed, 13 insertions(+), 37 deletions(-) diff --git a/Include/cpython/pystate.h b/Include/cpython/pystate.h index a1130381886ca78..628f2e0996e4695 100644 --- a/Include/cpython/pystate.h +++ b/Include/cpython/pystate.h @@ -143,15 +143,6 @@ struct _ts { /* padding to align to 4 bytes */ unsigned int :24; } _status; -#ifdef Py_BUILD_CORE -# define _PyThreadState_WHENCE_NOTSET -1 -# define _PyThreadState_WHENCE_UNKNOWN 0 -# define _PyThreadState_WHENCE_INTERP 1 -# define _PyThreadState_WHENCE_THREADING 2 -# define _PyThreadState_WHENCE_GILSTATE 3 -# define _PyThreadState_WHENCE_EXEC 4 -#endif - int _whence; int py_recursion_remaining; int py_recursion_limit; diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index 831e84060242a82..d243e0f03b78872 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -133,9 +133,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) { // PyThreadState functions -PyAPI_FUNC(PyThreadState *) _PyThreadState_New( - PyInterpreterState *interp, - int whence); +PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp); PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate); // We keep this around exclusively for stable ABI compatibility. PyAPI_FUNC(void) _PyThreadState_Init( diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index 035e0f595b92d89..7aace9f86119c41 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -127,7 +127,6 @@ extern PyTypeObject _PyExc_MemoryError; #define _PyThreadState_INIT \ { \ - ._whence = _PyThreadState_WHENCE_NOTSET, \ .py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \ .context_ver = 1, \ } diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index 598c096d8e9ee45..568fe8375d1eb4e 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -1203,7 +1203,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) if (boot == NULL) { return PyErr_NoMemory(); } - boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING); + boot->tstate = _PyThreadState_New(interp); if (boot->tstate == NULL) { PyMem_RawFree(boot); if (!PyErr_Occurred()) { diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index fda9bba428099b5..29fe9ca7eb92c35 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -483,7 +483,6 @@ _run_script_in_interpreter(PyObject *mod, PyInterpreterState *interp, PyThreadState *tstate = NULL; if (interp != PyInterpreterState_Get()) { tstate = PyThreadState_New(interp); - tstate->_whence = _PyThreadState_WHENCE_EXEC; // XXX Possible GILState issues? save_tstate = PyThreadState_Swap(tstate); } @@ -611,7 +610,6 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds) // Destroy the interpreter. PyThreadState *tstate = PyThreadState_New(interp); - tstate->_whence = _PyThreadState_WHENCE_INTERP; // XXX Possible GILState issues? PyThreadState *save_tstate = PyThreadState_Swap(tstate); Py_EndInterpreter(tstate); diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 7af3620b66d28a5..29771e07ae6a2c4 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -650,8 +650,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime, return status; } - PyThreadState *tstate = _PyThreadState_New(interp, - _PyThreadState_WHENCE_INTERP); + PyThreadState *tstate = _PyThreadState_New(interp); if (tstate == NULL) { return _PyStatus_ERR("can't make first thread"); } @@ -2026,8 +2025,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config) return _PyStatus_OK(); } - PyThreadState *tstate = _PyThreadState_New(interp, - _PyThreadState_WHENCE_INTERP); + PyThreadState *tstate = _PyThreadState_New(interp); if (tstate == NULL) { PyInterpreterState_Delete(interp); *tstate_p = NULL; diff --git a/Python/pystate.c b/Python/pystate.c index debf0447f531077..c4f81a0a0d9f90d 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1073,7 +1073,6 @@ _PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp) // thread, so it was set as threading._main_thread. (See gh-75698.) // The thread has finished running the Python program so we mark // the thread object as finished. - assert(tstate->_whence != _PyThreadState_WHENCE_THREADING); tstate->on_delete(tstate->on_delete_data); tstate->on_delete = NULL; tstate->on_delete_data = NULL; @@ -1159,8 +1158,7 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp) PyThread_release_lock(interp->id_mutex); if (refcount == 0 && interp->requires_idref) { - PyThreadState *tstate = _PyThreadState_New(interp, - _PyThreadState_WHENCE_INTERP); + PyThreadState *tstate = _PyThreadState_New(interp); _PyThreadState_Bind(tstate); // XXX Possible GILState issues? @@ -1338,7 +1336,7 @@ free_threadstate(PyThreadState *tstate) static void init_threadstate(PyThreadState *tstate, - PyInterpreterState *interp, uint64_t id, int whence) + PyInterpreterState *interp, uint64_t id) { if (tstate->_status.initialized) { Py_FatalError("thread state already initialized"); @@ -1351,10 +1349,6 @@ init_threadstate(PyThreadState *tstate, assert(tstate->next == NULL); assert(tstate->prev == NULL); - assert(tstate->_whence == _PyThreadState_WHENCE_NOTSET); - assert(whence >= 0 && whence <= _PyThreadState_WHENCE_EXEC); - tstate->_whence = whence; - assert(id > 0); tstate->id = id; @@ -1394,7 +1388,7 @@ add_threadstate(PyInterpreterState *interp, PyThreadState *tstate, } static PyThreadState * -new_threadstate(PyInterpreterState *interp, int whence) +new_threadstate(PyInterpreterState *interp) { PyThreadState *tstate; _PyRuntimeState *runtime = interp->runtime; @@ -1433,7 +1427,7 @@ new_threadstate(PyInterpreterState *interp, int whence) sizeof(*tstate)); } - init_threadstate(tstate, interp, id, whence); + init_threadstate(tstate, interp, id); add_threadstate(interp, tstate, old_head); HEAD_UNLOCK(runtime); @@ -1447,8 +1441,7 @@ new_threadstate(PyInterpreterState *interp, int whence) PyThreadState * PyThreadState_New(PyInterpreterState *interp) { - PyThreadState *tstate = new_threadstate(interp, - _PyThreadState_WHENCE_UNKNOWN); + PyThreadState *tstate = new_threadstate(interp); if (tstate) { bind_tstate(tstate); // This makes sure there's a gilstate tstate bound @@ -1462,16 +1455,16 @@ PyThreadState_New(PyInterpreterState *interp) // This must be followed by a call to _PyThreadState_Bind(); PyThreadState * -_PyThreadState_New(PyInterpreterState *interp, int whence) +_PyThreadState_New(PyInterpreterState *interp) { - return new_threadstate(interp, whence); + return new_threadstate(interp); } // We keep this for stable ABI compabibility. PyThreadState * _PyThreadState_Prealloc(PyInterpreterState *interp) { - return _PyThreadState_New(interp, _PyThreadState_WHENCE_UNKNOWN); + return _PyThreadState_New(interp); } // We keep this around for (accidental) stable ABI compatibility. @@ -2235,8 +2228,7 @@ PyGILState_Ensure(void) if (tcur == NULL) { /* Create a new Python thread state for this thread */ // XXX Use PyInterpreterState_EnsureThreadState()? - tcur = new_threadstate(runtime->gilstate.autoInterpreterState, - _PyThreadState_WHENCE_GILSTATE); + tcur = new_threadstate(runtime->gilstate.autoInterpreterState); if (tcur == NULL) { Py_FatalError("Couldn't create thread-state for new thread"); }