Skip to content

Commit 22c6fd0

Browse files
_PyThreadState_Prealloc() -> _PyThreadState_New()
1 parent 8c5596a commit 22c6fd0

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

Include/cpython/pystate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ struct _ts {
266266
// Alias for backward compatibility with Python 3.8
267267
#define _PyInterpreterState_Get PyInterpreterState_Get
268268

269-
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
270-
271269
/* Similar to PyThreadState_Get(), but don't issue a fatal error
272270
* if it is NULL. */
273271
PyAPI_FUNC(PyThreadState *) _PyThreadState_UncheckedGet(void);

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
120120

121121
// PyThreadState functions
122122

123+
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
123124
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
124125
// We keep this around exclusively for stable ABI compatibility.
125126
PyAPI_FUNC(void) _PyThreadState_Init(

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
11611161
return PyErr_NoMemory();
11621162
}
11631163
boot->interp = _PyInterpreterState_GET();
1164-
boot->tstate = _PyThreadState_Prealloc(boot->interp);
1164+
boot->tstate = _PyThreadState_New(boot->interp);
11651165
if (boot->tstate == NULL) {
11661166
PyMem_Free(boot);
11671167
if (!PyErr_Occurred()) {

Python/pylifecycle.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,11 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
696696
const _PyInterpreterConfig config = _PyInterpreterConfig_LEGACY_INIT;
697697
init_interp_settings(interp, &config);
698698

699-
PyThreadState *tstate = PyThreadState_New(interp);
699+
PyThreadState *tstate = _PyThreadState_New(interp);
700700
if (tstate == NULL) {
701701
return _PyStatus_ERR("can't make first thread");
702702
}
703+
_PyThreadState_Bind(tstate);
703704
(void) PyThreadState_Swap(tstate);
704705

705706
status = init_interp_create_gil(tstate);
@@ -2074,12 +2075,13 @@ new_interpreter(PyThreadState **tstate_p, const _PyInterpreterConfig *config)
20742075
return _PyStatus_OK();
20752076
}
20762077

2077-
PyThreadState *tstate = PyThreadState_New(interp);
2078+
PyThreadState *tstate = _PyThreadState_New(interp);
20782079
if (tstate == NULL) {
20792080
PyInterpreterState_Delete(interp);
20802081
*tstate_p = NULL;
20812082
return _PyStatus_OK();
20822083
}
2084+
_PyThreadState_Bind(tstate);
20832085

20842086
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
20852087

Python/pystate.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ PyThreadState_New(PyInterpreterState *interp)
12511251

12521252
// This must be followed by a call to _PyThreadState_Bind();
12531253
PyThreadState *
1254-
_PyThreadState_Prealloc(PyInterpreterState *interp)
1254+
_PyThreadState_New(PyInterpreterState *interp)
12551255
{
12561256
return new_threadstate(interp);
12571257
}
@@ -2066,10 +2066,11 @@ PyGILState_Ensure(void)
20662066
int has_gil;
20672067
if (tcur == NULL) {
20682068
/* Create a new Python thread state for this thread */
2069-
tcur = PyThreadState_New(runtime->gilstate.autoInterpreterState);
2069+
tcur = new_threadstate(runtime->gilstate.autoInterpreterState);
20702070
if (tcur == NULL) {
20712071
Py_FatalError("Couldn't create thread-state for new thread");
20722072
}
2073+
bind_tstate(tcur);
20732074

20742075
/* This is our thread state! We'll need to delete it in the
20752076
matching call to PyGILState_Release(). */

0 commit comments

Comments
 (0)