Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Prev Previous commit
Next Next commit
Call _PyThreadState_GET() from _PyRuntimeState_GetThreadState().
  • Loading branch information
ericsnowcurrently committed Apr 7, 2023
commit d57305336a00b68563b59ac6dfdd424f18e2a998
22 changes: 11 additions & 11 deletions Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,15 @@ extern _Py_thread_local PyThreadState *_Py_tss_tstate;
#endif
PyAPI_DATA(PyThreadState *) _PyThreadState_GetCurrent(void);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use case for this new _PyThreadState_GetCurrent() function? There is already PyThreadState_Get(). How is it different?

The API to get the current thread state is already complicated and has a complicated history: https://pythondev.readthedocs.io/pystate.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's there because I couldn't find a way to mix PyAPI_DATA with _Py_thread_local. Looks like that's the same issue you ran into in 2020.


/* Get the current Python thread state.

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

The caller must hold the GIL.

See also PyThreadState_Get() and _PyThreadState_UncheckedGet(). */
static inline PyThreadState*
_PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
_PyThreadState_GET(void)
{
#if defined(HAVE_THREAD_LOCAL) && !defined(Py_BUILD_CORE_MODULE)
return _Py_tss_tstate;
Expand All @@ -79,20 +86,13 @@ _PyRuntimeState_GetThreadState(_PyRuntimeState *runtime)
#endif
}


/* Get the current Python thread state.

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

The caller must hold the GIL.

See also PyThreadState_Get() and _PyThreadState_UncheckedGet(). */
static inline PyThreadState*
_PyThreadState_GET(void)
_PyRuntimeState_GetThreadState(_PyRuntimeState *Py_UNUSED(runtime))
{
return _PyRuntimeState_GetThreadState(&_PyRuntime);
return _PyThreadState_GET();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function no longer makes sense: I wrote PR #104171 to remove it.

}


static inline void
_Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
{
Expand Down