gh-108867: Add PyThreadState_GetUnchecked() function#108870
gh-108867: Add PyThreadState_GetUnchecked() function#108870vstinner merged 2 commits intopython:mainfrom
Conversation
c180b5b to
572f4a4
Compare
|
I was worried about /* Python 3.9 private API, invoked by the macros below. */
PyAPI_FUNC(int) _PyTrash_begin(PyThreadState *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_end(PyThreadState *tstate);
/* Python 3.10 private API, invoked by the Py_TRASHCAN_BEGIN(). */
PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);I was worried that we still provide Python 3.9 functions. Is it the a stable ABI? Nope, these functions are not part of Moreover, I explicitly removed the following macros from the limited C API in Python 3.9:
So in fact, we keep Python 3.9 functions for the ABI backward compatibility, whereas we do not support these APIs in the stable ABI. In short, it's ok to rename |
|
A bunch of projects currently uses Affected projects (18):
In this list, IMO the interesting one is Cython: $ git grep -E '(_PyThreadState_UncheckedGet|__Pyx_PyThreadState_Current)'
Cython/Utility/AsyncGen.c: tstate = __Pyx_PyThreadState_Current;
Cython/Utility/AsyncGen.c: tstate = __Pyx_PyThreadState_Current;
Cython/Utility/Coroutine.c: __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue)
Cython/Utility/Coroutine.c: tstate = __Pyx_PyThreadState_Current;
Cython/Utility/Coroutine.c: __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val);
Cython/Utility/Exceptions.c: __pyx_assertions_enabled_flag = ! _PyInterpreterState_GetConfig(__Pyx_PyThreadState_Current->interp)->optimization_level;
Cython/Utility/Exceptions.c:#define __Pyx_PyThreadState_assign $local_tstate_cname = __Pyx_PyThreadState_Current;
Cython/Utility/Exceptions.c: PyThreadState *tstate = __Pyx_PyThreadState_Current;
Cython/Utility/Exceptions.c: (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line);
Cython/Utility/Exceptions.c: PyThreadState *tstate = __Pyx_PyThreadState_Current;
Cython/Utility/ModuleSetupCode.c: // Py3<3.5.2 does not support _PyThreadState_UncheckedGet().
Cython/Utility/ModuleSetupCode.c: #define __Pyx_PyThreadState_Current PyThreadState_Get()
Cython/Utility/ModuleSetupCode.c: #define __Pyx_PyThreadState_Current PyThreadState_GET()
Cython/Utility/ModuleSetupCode.c: #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet()
Cython/Utility/ModuleSetupCode.c: #define __Pyx_PyThreadState_Current PyThreadState_GET()
Cython/Utility/ModuleSetupCode.c: #define __Pyx_PyThreadState_Current _PyThreadState_Current
Cython/Utility/ModuleSetupCode.c: current = tcur == __Pyx_PyThreadState_Current;
Cython/Utility/ObjectHandling.c: PyThreadState *tstate = __Pyx_PyThreadState_Current;
Cython/Utility/Profile.c: tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: PyThreadState* tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: PyThreadState* tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: PyThreadState* tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: PyThreadState* tstate = __Pyx_PyThreadState_Current; \
Cython/Utility/Profile.c: PyThreadState* tstate = __Pyx_PyThreadState_Current; \I can easily add PyThreadState_GetUnsafe() to pythoncapi-compat by calling |
|
I asked in the C API Working Group which function name is better: use Unchecked suffix or Unsafe suffix? |
|
I renamed the function to PyThreadState_GetUnchecked() and addressed @encukou's suggestion on the documentation. |
cddb3cc to
92b23e7
Compare
Add PyThreadState_GetUnchecked() function: similar to PyThreadState_Get(), but don't issue a fatal error if it is NULL. The caller is responsible to check if the result is NULL. Previously, this function was private and known as _PyThreadState_UncheckedGet().
92b23e7 to
2372091
Compare
Oops, my PR still used PyThreadState_GetUnsafe() name. I messed up something. Anyway, I updated it again, and now it uses PyThreadState_GetUnchecked() name everywhere. |
|
I added PyThreadState_GetUnchecked() to pythoncapi-compat: python/pythoncapi-compat@f78c780 |
…8870) Add PyThreadState_GetUnchecked() function: similar to PyThreadState_Get(), but don't issue a fatal error if it is NULL. The caller is responsible to check if the result is NULL. Previously, this function was private and known as _PyThreadState_UncheckedGet().
Add PyThreadState_GetUnchecked() function: similar to
PyThreadState_Get(), but don't issue a fatal error if it is NULL. The
caller is responsible to check if the result is NULL. Previously,
this function was private and known as _PyThreadState_UncheckedGet().
📚 Documentation preview 📚: https://cpython-previews--108870.org.readthedocs.build/