Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-103323: Remove PyRuntimeState_GetThreadState() #104171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions 10 Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ _Py_ThreadCanHandlePendingCalls(void)
}


/* Variable and macro for in-line access to current thread
/* Variable and static inline functions for in-line access to current thread
and interpreter state */

#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
Expand All @@ -93,12 +93,6 @@ _PyThreadState_GET(void)
#endif
}

static inline PyThreadState*
_PyRuntimeState_GetThreadState(_PyRuntimeState *Py_UNUSED(runtime))
{
return _PyThreadState_GET();
}


static inline void
_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
Expand All @@ -118,7 +112,7 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)

/* Get the current interpreter state.

The macro is unsafe: it does not check for error and it can return NULL.
The function is unsafe: it does not check for error and it can return NULL.

The caller must hold the GIL.

Expand Down
5 changes: 2 additions & 3 deletions 5 Python/ceval_gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,7 @@ _PyEval_Fini(void)
void
PyEval_AcquireLock(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyThreadState *tstate = _PyThreadState_GET();
_Py_EnsureTstateNotNULL(tstate);

take_gil(tstate);
Expand All @@ -557,7 +556,7 @@ void
PyEval_ReleaseLock(void)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyThreadState *tstate = _PyThreadState_GET();
/* This function must succeed when the current thread state is NULL.
We therefore avoid PyThreadState_Get() which dumps a fatal error
in debug mode. */
Expand Down
7 changes: 3 additions & 4 deletions 7 Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,7 @@ _Py_InitializeMain(void)
if (_PyStatus_EXCEPTION(status)) {
return status;
}
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyThreadState *tstate = _PyThreadState_GET();
return pyinit_main(tstate);
}

Expand Down Expand Up @@ -1755,7 +1754,7 @@ Py_FinalizeEx(void)
}

/* Get current thread state and interpreter pointer */
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyThreadState *tstate = _PyThreadState_GET();
// XXX assert(_Py_IsMainInterpreter(tstate->interp));
// XXX assert(_Py_IsMainThread());

Expand Down Expand Up @@ -2800,7 +2799,7 @@ fatal_error(int fd, int header, const char *prefix, const char *msg,

tss_tstate != tstate if the current Python thread does not hold the GIL.
*/
PyThreadState *tstate = _PyRuntimeState_GetThreadState(runtime);
PyThreadState *tstate = _PyThreadState_GET();
PyInterpreterState *interp = NULL;
PyThreadState *tss_tstate = PyGILState_GetThisThreadState();
if (tstate != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion 2 Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,7 @@ int
PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
{
_PyRuntimeState *runtime = &_PyRuntime;
PyInterpreterState *interp = _PyRuntimeState_GetThreadState(runtime)->interp;
PyInterpreterState *interp = _PyInterpreterState_GET();

/* Although the GIL is held, a few C API functions can be called
* without the GIL held, and in particular some that create and
Expand Down
2 changes: 1 addition & 1 deletion 2 Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
_PyRuntimeState *runtime = &_PyRuntime;
PyThreadState *tstate;
if (runtime->initialized) {
tstate = _PyRuntimeState_GetThreadState(runtime);
tstate = _PyThreadState_GET();
}
else {
tstate = NULL;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.