bpo-35081: Add _PyThreadState_GET() internal macro by vstinner · Pull Request #10266 · python/cpython (original) (raw)

vstinner

PyThreadState_GET() is a macro accessing
_PyRuntime.gilstate.tstate_current variable or calling
PyThreadState_Get() depending on Py_BUILD_CORE.

Add a new _PyThreadState_GET() internal macro which is always
the efficient macro accessing directly the variable. _PyThreadState_GET()
is not available if Py_BUILD_CORE is not defined.

Changes:

https://bugs.python.org/issue35081

@vstinner

Travis CI failed on running doctests:

xvfb-run:
   error:
   Xvfb
   failed
   to
   start

@vstinner

If Py_BUILD_CORE is defined, the PyThreadState_GET() macro access _PyRuntime which comes from the internal pycore_state.h header. Public headers must not require internal headers.

Move PyThreadState_GET() and _PyInterpreterState_GET_UNSAFE() from Include/pystate.h to Include/internal/pycore_state.h, and rename PyThreadState_GET() to _PyThreadState_GET() there.

The PyThreadState_GET() macro of pystate.h is now redefined when pycore_state.h is included, to use the fast _PyThreadState_GET().

Changes:

@vstinner