gh-103323: Remove current_fast_get() unused parameter (#114593)

The current_fast_get() static inline function doesn't use its
'runtime' parameter, so just remove it.
This commit is contained in:
Victor Stinner 2024-01-30 11:47:58 +01:00 committed by GitHub
parent 963904335e
commit 58f883b91b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 24 additions and 26 deletions

View File

@ -67,7 +67,7 @@ _Py_thread_local PyThreadState *_Py_tss_tstate = NULL;
#endif #endif
static inline PyThreadState * static inline PyThreadState *
current_fast_get(_PyRuntimeState *Py_UNUSED(runtime)) current_fast_get(void)
{ {
#ifdef HAVE_THREAD_LOCAL #ifdef HAVE_THREAD_LOCAL
return _Py_tss_tstate; return _Py_tss_tstate;
@ -101,14 +101,14 @@ current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
} }
#define tstate_verify_not_active(tstate) \ #define tstate_verify_not_active(tstate) \
if (tstate == current_fast_get((tstate)->interp->runtime)) { \ if (tstate == current_fast_get()) { \
_Py_FatalErrorFormat(__func__, "tstate %p is still current", tstate); \ _Py_FatalErrorFormat(__func__, "tstate %p is still current", tstate); \
} }
PyThreadState * PyThreadState *
_PyThreadState_GetCurrent(void) _PyThreadState_GetCurrent(void)
{ {
return current_fast_get(&_PyRuntime); return current_fast_get();
} }
@ -360,10 +360,9 @@ holds_gil(PyThreadState *tstate)
// XXX Fall back to tstate->interp->runtime->ceval.gil.last_holder // XXX Fall back to tstate->interp->runtime->ceval.gil.last_holder
// (and tstate->interp->runtime->ceval.gil.locked). // (and tstate->interp->runtime->ceval.gil.locked).
assert(tstate != NULL); assert(tstate != NULL);
_PyRuntimeState *runtime = tstate->interp->runtime;
/* Must be the tstate for this thread */ /* Must be the tstate for this thread */
assert(tstate == gilstate_tss_get(runtime)); assert(tstate == gilstate_tss_get(tstate->interp->runtime));
return tstate == current_fast_get(runtime); return tstate == current_fast_get();
} }
@ -723,7 +722,7 @@ PyInterpreterState *
PyInterpreterState_New(void) PyInterpreterState_New(void)
{ {
// tstate can be NULL // tstate can be NULL
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
PyInterpreterState *interp; PyInterpreterState *interp;
PyStatus status = _PyInterpreterState_New(tstate, &interp); PyStatus status = _PyInterpreterState_New(tstate, &interp);
@ -882,7 +881,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
// Use the current Python thread state to call audit hooks and to collect // Use the current Python thread state to call audit hooks and to collect
// garbage. It can be different than the current Python thread state // garbage. It can be different than the current Python thread state
// of 'interp'. // of 'interp'.
PyThreadState *current_tstate = current_fast_get(interp->runtime); PyThreadState *current_tstate = current_fast_get();
_PyImport_ClearCore(interp); _PyImport_ClearCore(interp);
interpreter_clear(interp, current_tstate); interpreter_clear(interp, current_tstate);
} }
@ -908,7 +907,7 @@ PyInterpreterState_Delete(PyInterpreterState *interp)
// XXX Clearing the "current" thread state should happen before // XXX Clearing the "current" thread state should happen before
// we start finalizing the interpreter (or the current thread state). // we start finalizing the interpreter (or the current thread state).
PyThreadState *tcur = current_fast_get(runtime); PyThreadState *tcur = current_fast_get();
if (tcur != NULL && interp == tcur->interp) { if (tcur != NULL && interp == tcur->interp) {
/* Unset current thread. After this, many C API calls become crashy. */ /* Unset current thread. After this, many C API calls become crashy. */
_PyThreadState_Detach(tcur); _PyThreadState_Detach(tcur);
@ -1010,7 +1009,7 @@ _PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
if (_PyInterpreterState_FailIfRunningMain(interp) < 0) { if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
return -1; return -1;
} }
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
if (tstate->interp != interp) { if (tstate->interp != interp) {
PyErr_SetString(PyExc_RuntimeError, PyErr_SetString(PyExc_RuntimeError,
@ -1025,7 +1024,7 @@ void
_PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
{ {
PyThreadState *tstate = interp->threads.main; PyThreadState *tstate = interp->threads.main;
assert(tstate == current_fast_get(&_PyRuntime)); assert(tstate == current_fast_get());
if (tstate->on_delete != NULL) { if (tstate->on_delete != NULL) {
// The threading module was imported for the first time in this // The threading module was imported for the first time in this
@ -1178,7 +1177,7 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
PyInterpreterState* PyInterpreterState*
PyInterpreterState_Get(void) PyInterpreterState_Get(void)
{ {
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
PyInterpreterState *interp = tstate->interp; PyInterpreterState *interp = tstate->interp;
if (interp == NULL) { if (interp == NULL) {
@ -1474,7 +1473,7 @@ void
PyThreadState_Clear(PyThreadState *tstate) PyThreadState_Clear(PyThreadState *tstate)
{ {
assert(tstate->_status.initialized && !tstate->_status.cleared); assert(tstate->_status.initialized && !tstate->_status.cleared);
assert(current_fast_get(&_PyRuntime)->interp == tstate->interp); assert(current_fast_get()->interp == tstate->interp);
// XXX assert(!tstate->_status.bound || tstate->_status.unbound); // XXX assert(!tstate->_status.bound || tstate->_status.unbound);
tstate->_status.finalizing = 1; // just in case tstate->_status.finalizing = 1; // just in case
@ -1656,7 +1655,7 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
void void
PyThreadState_DeleteCurrent(void) PyThreadState_DeleteCurrent(void)
{ {
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
_PyThreadState_DeleteCurrent(tstate); _PyThreadState_DeleteCurrent(tstate);
} }
@ -1732,7 +1731,7 @@ _PyThreadState_GetDict(PyThreadState *tstate)
PyObject * PyObject *
PyThreadState_GetDict(void) PyThreadState_GetDict(void)
{ {
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
if (tstate == NULL) { if (tstate == NULL) {
return NULL; return NULL;
} }
@ -1853,7 +1852,7 @@ _PyThreadState_Attach(PyThreadState *tstate)
#endif #endif
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
if (current_fast_get(&_PyRuntime) != NULL) { if (current_fast_get() != NULL) {
Py_FatalError("non-NULL old thread state"); Py_FatalError("non-NULL old thread state");
} }
@ -1883,7 +1882,7 @@ detach_thread(PyThreadState *tstate, int detached_state)
{ {
// XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate)); // XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate));
assert(tstate->state == _Py_THREAD_ATTACHED); assert(tstate->state == _Py_THREAD_ATTACHED);
assert(tstate == current_fast_get(&_PyRuntime)); assert(tstate == current_fast_get());
if (tstate->critical_section != 0) { if (tstate->critical_section != 0) {
_PyCriticalSection_SuspendAll(tstate); _PyCriticalSection_SuspendAll(tstate);
} }
@ -2168,14 +2167,14 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
PyThreadState * PyThreadState *
PyThreadState_GetUnchecked(void) PyThreadState_GetUnchecked(void)
{ {
return current_fast_get(&_PyRuntime); return current_fast_get();
} }
PyThreadState * PyThreadState *
PyThreadState_Get(void) PyThreadState_Get(void)
{ {
PyThreadState *tstate = current_fast_get(&_PyRuntime); PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
return tstate; return tstate;
} }
@ -2183,7 +2182,7 @@ PyThreadState_Get(void)
PyThreadState * PyThreadState *
_PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts) _PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
{ {
PyThreadState *oldts = current_fast_get(runtime); PyThreadState *oldts = current_fast_get();
if (oldts != NULL) { if (oldts != NULL) {
_PyThreadState_Detach(oldts); _PyThreadState_Detach(oldts);
} }
@ -2278,7 +2277,7 @@ PyObject *
_PyThread_CurrentFrames(void) _PyThread_CurrentFrames(void)
{ {
_PyRuntimeState *runtime = &_PyRuntime; _PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = current_fast_get(runtime); PyThreadState *tstate = current_fast_get();
if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) { if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
return NULL; return NULL;
} }
@ -2339,7 +2338,7 @@ PyObject *
_PyThread_CurrentExceptions(void) _PyThread_CurrentExceptions(void)
{ {
_PyRuntimeState *runtime = &_PyRuntime; _PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = current_fast_get(runtime); PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
@ -2481,7 +2480,7 @@ PyGILState_Check(void)
return 1; return 1;
} }
PyThreadState *tstate = current_fast_get(runtime); PyThreadState *tstate = current_fast_get();
if (tstate == NULL) { if (tstate == NULL) {
return 0; return 0;
} }
@ -2579,7 +2578,7 @@ PyGILState_Release(PyGILState_STATE oldstate)
* races; see bugs 225673 and 1061968 (that nasty bug has a * races; see bugs 225673 and 1061968 (that nasty bug has a
* habit of coming back). * habit of coming back).
*/ */
assert(current_fast_get(runtime) == tstate); assert(current_fast_get() == tstate);
_PyThreadState_DeleteCurrent(tstate); _PyThreadState_DeleteCurrent(tstate);
} }
/* Release the lock if necessary */ /* Release the lock if necessary */
@ -2645,9 +2644,8 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
const PyConfig* const PyConfig*
_Py_GetConfig(void) _Py_GetConfig(void)
{ {
_PyRuntimeState *runtime = &_PyRuntime;
assert(PyGILState_Check()); assert(PyGILState_Check());
PyThreadState *tstate = current_fast_get(runtime); PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate); _Py_EnsureTstateNotNULL(tstate);
return _PyInterpreterState_GetConfig(tstate->interp); return _PyInterpreterState_GetConfig(tstate->interp);
} }