// PyThreadState functions
+PyAPI_FUNC(void) _PyThreadState_SetCurrent(PyThreadState *tstate);
+// We keep this around exclusively for stable ABI compatibility.
PyAPI_FUNC(void) _PyThreadState_Init(
PyThreadState *tstate);
PyAPI_FUNC(void) _PyThreadState_DeleteExcept(
#include "pycore_interp.h" // _PyInterpreterState.threads.count
#include "pycore_moduleobject.h" // _PyModule_GetState()
#include "pycore_pylifecycle.h"
-#include "pycore_pystate.h" // _PyThreadState_Init()
+#include "pycore_pystate.h" // _PyThreadState_SetCurrent()
#include <stddef.h> // offsetof()
#include "structmember.h" // PyMemberDef
#else
tstate->native_thread_id = 0;
#endif
- _PyThreadState_Init(tstate);
+ _PyThreadState_SetCurrent(tstate);
PyEval_AcquireThread(tstate);
tstate->interp->threads.count++;
}
static PyThreadState *
-new_threadstate(PyInterpreterState *interp, int init)
+new_threadstate(PyInterpreterState *interp)
{
_PyRuntimeState *runtime = interp->runtime;
PyThreadState *tstate = (PyThreadState *)PyMem_RawCalloc(1, sizeof(PyThreadState));
tstate->datastack_top = &tstate->datastack_chunk->data[1];
tstate->datastack_limit = (PyObject **)(((char *)tstate->datastack_chunk) + DATA_STACK_CHUNK_SIZE);
- if (init) {
- _PyThreadState_Init(tstate);
- }
-
HEAD_LOCK(runtime);
tstate->id = ++interp->threads.next_unique_id;
tstate->next = interp->threads.head;
PyThreadState *
PyThreadState_New(PyInterpreterState *interp)
{
- return new_threadstate(interp, 1);
+ PyThreadState *tstate = new_threadstate(interp);
+ _PyThreadState_SetCurrent(tstate);
+ return tstate;
}
PyThreadState *
_PyThreadState_Prealloc(PyInterpreterState *interp)
{
- return new_threadstate(interp, 0);
+ return new_threadstate(interp);
}
+// We keep this around for (accidental) stable ABI compatibility.
+// Realisically, no extensions are using it.
void
_PyThreadState_Init(PyThreadState *tstate)
+{
+ Py_FatalError("_PyThreadState_Init() is for internal use only");
+}
+
+void
+_PyThreadState_SetCurrent(PyThreadState *tstate)
{
_PyGILState_NoteThreadState(&tstate->interp->runtime->gilstate, tstate);
}