summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-12-08 00:26:29 (GMT)
committerGitHub <noreply@github.com>2021-12-08 00:26:29 (GMT)
commit1f384e318481532323bb9076f4447bc02da07209 (patch)
tree41a6930e45fffdae2fa98b83fc1c94f3087115bd /Python
parent9b577cd01f66512b503115c0fdbf0734edfd5f8a (diff)
downloadcpython-1f384e318481532323bb9076f4447bc02da07209.zip
cpython-1f384e318481532323bb9076f4447bc02da07209.tar.gz
cpython-1f384e318481532323bb9076f4447bc02da07209.tar.bz2
bpo-46008: Stop calling _PyThreadState_Init() in new_threadstate(). (gh-29973)
This simplifies new_threadstate(). We also rename _PyThreadState_Init() to _PyThreadState_SetCurrent() to reflect what it actually does. https://bugs.python.org/issue46008
Diffstat (limited to 'Python')
-rw-r--r--Python/pystate.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/Python/pystate.c b/Python/pystate.c
index 49acd56..f94019d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -631,7 +631,7 @@ allocate_chunk(int size_in_bytes, _PyStackChunk* previous)
}
static PyThreadState *
-new_threadstate(PyInterpreterState *interp, int init)
+new_threadstate(PyInterpreterState *interp)
{
_PyRuntimeState *runtime = interp->runtime;
PyThreadState *tstate = (PyThreadState *)PyMem_RawCalloc(1, sizeof(PyThreadState));
@@ -662,10 +662,6 @@ new_threadstate(PyInterpreterState *interp, int init)
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;
@@ -680,18 +676,28 @@ new_threadstate(PyInterpreterState *interp, int init)
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);
}