Skip to content

Commit

Permalink
pythongh-103323: Remove current_fast_get() unused parameter (python#1…
Browse files Browse the repository at this point in the history
…14593)

The current_fast_get() static inline function doesn't use its
'runtime' parameter, so just remove it.
  • Loading branch information
vstinner authored and aisk committed Feb 11, 2024
1 parent dec95a6 commit b81e357
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ _Py_thread_local PyThreadState *_Py_tss_tstate = NULL;
#endif

static inline PyThreadState *
current_fast_get(_PyRuntimeState *Py_UNUSED(runtime))
current_fast_get(void)
{
#ifdef HAVE_THREAD_LOCAL
return _Py_tss_tstate;
Expand Down Expand Up @@ -101,14 +101,14 @@ current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
}

#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); \
}

PyThreadState *
_PyThreadState_GetCurrent(void)
{
return current_fast_get(&_PyRuntime);
return current_fast_get();
}


Expand Down Expand Up @@ -360,10 +360,9 @@ holds_gil(PyThreadState *tstate)
// XXX Fall back to tstate->interp->runtime->ceval.gil.last_holder
// (and tstate->interp->runtime->ceval.gil.locked).
assert(tstate != NULL);
_PyRuntimeState *runtime = tstate->interp->runtime;
/* Must be the tstate for this thread */
assert(tstate == gilstate_tss_get(runtime));
return tstate == current_fast_get(runtime);
assert(tstate == gilstate_tss_get(tstate->interp->runtime));
return tstate == current_fast_get();
}


Expand Down Expand Up @@ -723,7 +722,7 @@ PyInterpreterState *
PyInterpreterState_New(void)
{
// tstate can be NULL
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();

PyInterpreterState *interp;
PyStatus status = _PyInterpreterState_New(tstate, &interp);
Expand Down Expand Up @@ -882,7 +881,7 @@ PyInterpreterState_Clear(PyInterpreterState *interp)
// Use the current Python thread state to call audit hooks and to collect
// garbage. It can be different than the current Python thread state
// of 'interp'.
PyThreadState *current_tstate = current_fast_get(interp->runtime);
PyThreadState *current_tstate = current_fast_get();
_PyImport_ClearCore(interp);
interpreter_clear(interp, current_tstate);
}
Expand All @@ -908,7 +907,7 @@ PyInterpreterState_Delete(PyInterpreterState *interp)

// XXX Clearing the "current" thread state should happen before
// 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) {
/* Unset current thread. After this, many C API calls become crashy. */
_PyThreadState_Detach(tcur);
Expand Down Expand Up @@ -1010,7 +1009,7 @@ _PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
return -1;
}
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
if (tstate->interp != interp) {
PyErr_SetString(PyExc_RuntimeError,
Expand All @@ -1025,7 +1024,7 @@ void
_PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
{
PyThreadState *tstate = interp->threads.main;
assert(tstate == current_fast_get(&_PyRuntime));
assert(tstate == current_fast_get());

if (tstate->on_delete != NULL) {
// The threading module was imported for the first time in this
Expand Down Expand Up @@ -1178,7 +1177,7 @@ PyInterpreterState_GetDict(PyInterpreterState *interp)
PyInterpreterState*
PyInterpreterState_Get(void)
{
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
PyInterpreterState *interp = tstate->interp;
if (interp == NULL) {
Expand Down Expand Up @@ -1474,7 +1473,7 @@ void
PyThreadState_Clear(PyThreadState *tstate)
{
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);
tstate->_status.finalizing = 1; // just in case

Expand Down Expand Up @@ -1656,7 +1655,7 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
void
PyThreadState_DeleteCurrent(void)
{
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();
_PyThreadState_DeleteCurrent(tstate);
}

Expand Down Expand Up @@ -1732,7 +1731,7 @@ _PyThreadState_GetDict(PyThreadState *tstate)
PyObject *
PyThreadState_GetDict(void)
{
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();
if (tstate == NULL) {
return NULL;
}
Expand Down Expand Up @@ -1853,7 +1852,7 @@ _PyThreadState_Attach(PyThreadState *tstate)
#endif

_Py_EnsureTstateNotNULL(tstate);
if (current_fast_get(&_PyRuntime) != NULL) {
if (current_fast_get() != NULL) {
Py_FatalError("non-NULL old thread state");
}

Expand Down Expand Up @@ -1883,7 +1882,7 @@ detach_thread(PyThreadState *tstate, int detached_state)
{
// XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate));
assert(tstate->state == _Py_THREAD_ATTACHED);
assert(tstate == current_fast_get(&_PyRuntime));
assert(tstate == current_fast_get());
if (tstate->critical_section != 0) {
_PyCriticalSection_SuspendAll(tstate);
}
Expand Down Expand Up @@ -2168,22 +2167,22 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
PyThreadState *
PyThreadState_GetUnchecked(void)
{
return current_fast_get(&_PyRuntime);
return current_fast_get();
}


PyThreadState *
PyThreadState_Get(void)
{
PyThreadState *tstate = current_fast_get(&_PyRuntime);
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
return tstate;
}

PyThreadState *
_PyThreadState_Swap(_PyRuntimeState *runtime, PyThreadState *newts)
{
PyThreadState *oldts = current_fast_get(runtime);
PyThreadState *oldts = current_fast_get();
if (oldts != NULL) {
_PyThreadState_Detach(oldts);
}
Expand Down Expand Up @@ -2278,7 +2277,7 @@ PyObject *
_PyThread_CurrentFrames(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = current_fast_get(runtime);
PyThreadState *tstate = current_fast_get();
if (_PySys_Audit(tstate, "sys._current_frames", NULL) < 0) {
return NULL;
}
Expand Down Expand Up @@ -2339,7 +2338,7 @@ PyObject *
_PyThread_CurrentExceptions(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = current_fast_get(runtime);
PyThreadState *tstate = current_fast_get();

_Py_EnsureTstateNotNULL(tstate);

Expand Down Expand Up @@ -2481,7 +2480,7 @@ PyGILState_Check(void)
return 1;
}

PyThreadState *tstate = current_fast_get(runtime);
PyThreadState *tstate = current_fast_get();
if (tstate == NULL) {
return 0;
}
Expand Down Expand Up @@ -2579,7 +2578,7 @@ PyGILState_Release(PyGILState_STATE oldstate)
* races; see bugs 225673 and 1061968 (that nasty bug has a
* habit of coming back).
*/
assert(current_fast_get(runtime) == tstate);
assert(current_fast_get() == tstate);
_PyThreadState_DeleteCurrent(tstate);
}
/* Release the lock if necessary */
Expand Down Expand Up @@ -2645,9 +2644,8 @@ _PyInterpreterState_GetConfigCopy(PyConfig *config)
const PyConfig*
_Py_GetConfig(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
assert(PyGILState_Check());
PyThreadState *tstate = current_fast_get(runtime);
PyThreadState *tstate = current_fast_get();
_Py_EnsureTstateNotNULL(tstate);
return _PyInterpreterState_GetConfig(tstate->interp);
}
Expand Down

0 comments on commit b81e357

Please sign in to comment.