Skip to content

gh-117578: Fix inlining regression in PyType_GetModuleByDef() #123100

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
unsafe experiment: do not respect TLS access
  • Loading branch information
neonene committed Aug 20, 2024
commit 6e62c38ce334b1a04778097ff232bad08ae4a5e9
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static inline PyThreadState*
_PyThreadState_GET(void)
{
#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
return _Py_tss_tstate;
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&_PyRuntime.tstate_current);
#else
return _PyThreadState_GetCurrent();
#endif
Expand Down
1 change: 1 addition & 0 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ typedef struct pyruntimestate {
struct _pythread_runtime_state threads;
struct _signals_runtime_state signals;

PyThreadState *tstate_current;
/* Used for the thread state bound to the current thread. */
Py_tss_t autoTSSkey;

Expand Down
18 changes: 13 additions & 5 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,31 @@ current_fast_get(void)
#endif
}

static inline PyThreadState *
current_fast_get2(void)
{
return (PyThreadState*)_Py_atomic_load_ptr_relaxed(&_PyRuntime.tstate_current);
}

static inline void
current_fast_set(_PyRuntimeState *Py_UNUSED(runtime), PyThreadState *tstate)
{
assert(tstate != NULL);
#ifdef HAVE_THREAD_LOCAL
_Py_tss_tstate = tstate;
_Py_atomic_store_ptr_relaxed(&_PyRuntime.tstate_current, tstate);
#else
// XXX Fall back to the PyThread_tss_*() API.
# error "no supported thread-local variable storage classifier"
#endif
}

static inline void
current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
current_fast_clear(_PyRuntimeState *runtime)
{
#ifdef HAVE_THREAD_LOCAL
_Py_tss_tstate = NULL;
_Py_atomic_store_ptr_relaxed(&runtime->tstate_current, NULL);
#else
// XXX Fall back to the PyThread_tss_*() API.
# error "no supported thread-local variable storage classifier"
Expand All @@ -110,7 +118,7 @@ current_fast_clear(_PyRuntimeState *Py_UNUSED(runtime))
PyThreadState *
_PyThreadState_GetCurrent(void)
{
return current_fast_get();
return current_fast_get2();
}


Expand Down Expand Up @@ -1331,7 +1339,7 @@ _PyInterpreterState_RequireIDRef(PyInterpreterState *interp, int required)
PyInterpreterState*
PyInterpreterState_Get(void)
{
PyThreadState *tstate = current_fast_get();
PyThreadState *tstate = current_fast_get2();
_Py_EnsureTstateNotNULL(tstate);
PyInterpreterState *interp = tstate->interp;
if (interp == NULL) {
Expand Down Expand Up @@ -2412,14 +2420,14 @@ PyThreadState_SetAsyncExc(unsigned long id, PyObject *exc)
PyThreadState *
PyThreadState_GetUnchecked(void)
{
return current_fast_get();
return current_fast_get2();
}


PyThreadState *
PyThreadState_Get(void)
{
PyThreadState *tstate = current_fast_get();
PyThreadState *tstate = current_fast_get2();
_Py_EnsureTstateNotNULL(tstate);
return tstate;
}
Expand Down
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