bpo-35081: Move Include/pyatomic.c to Include/internal/ by vstinner · Pull Request #10239 · python/cpython (original) (raw)
The only backward incompatible change is that #include "pyatomic.h"
no longer works: #include "internal/pyatomic.h"
must be used instead... But this header is really specific to Python internals, its full content was surrounded by #ifdef Py_BUILD_CORE
. Third-party C extensions must not use Py_BUILD_CORE.
In know that in the past, debuggers like vmprof required to access _PyThreadState_Current, but:
- _PyThreadState_Current is now an alias to _PyRuntime.gilstate.tstate_current: _PyRuntime is designed to more "private", it is only defined in Include/internal/pystate.h.
- We now provide _PyThreadState_UncheckedGet(() and _PyGILState_GetInterpreterStateUnsafe() which are exported for such debuggers
I'm talking about this macro which requires pyatomic.h:
/* Variable and macro for in-line access to current thread state */
/* Assuming the current thread holds the GIL, this is the
PyThreadState for the current thread. */
#ifdef Py_BUILD_CORE
# define _PyThreadState_Current _PyRuntime.gilstate.tstate_current
# define PyThreadState_GET() \
((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current))
We don't want to export pyatomic.h because its the header leaks its implementation, and the implementation highly depend on the compiler and compiler flags. This header is included in Python.h but its content wasn't first protected by #ifdef Py_BUILD_CORE
which caused many troubles with C++ compilers for example.