Skip to content

Commit 4fb7f0f

Browse files
Drop PyThreadState.whence.
1 parent 9a3588e commit 4fb7f0f

File tree

7 files changed

+13
-37
lines changed

7 files changed

+13
-37
lines changed

Include/cpython/pystate.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,6 @@ struct _ts {
143143
/* padding to align to 4 bytes */
144144
unsigned int :24;
145145
} _status;
146-
#ifdef Py_BUILD_CORE
147-
# define _PyThreadState_WHENCE_NOTSET -1
148-
# define _PyThreadState_WHENCE_UNKNOWN 0
149-
# define _PyThreadState_WHENCE_INTERP 1
150-
# define _PyThreadState_WHENCE_THREADING 2
151-
# define _PyThreadState_WHENCE_GILSTATE 3
152-
# define _PyThreadState_WHENCE_EXEC 4
153-
#endif
154-
int _whence;
155146

156147
int py_recursion_remaining;
157148
int py_recursion_limit;

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ static inline PyInterpreterState* _PyInterpreterState_GET(void) {
133133

134134
// PyThreadState functions
135135

136-
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(
137-
PyInterpreterState *interp,
138-
int whence);
136+
PyAPI_FUNC(PyThreadState *) _PyThreadState_New(PyInterpreterState *interp);
139137
PyAPI_FUNC(void) _PyThreadState_Bind(PyThreadState *tstate);
140138
// We keep this around exclusively for stable ABI compatibility.
141139
PyAPI_FUNC(void) _PyThreadState_Init(

Include/internal/pycore_runtime_init.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ extern PyTypeObject _PyExc_MemoryError;
127127

128128
#define _PyThreadState_INIT \
129129
{ \
130-
._whence = _PyThreadState_WHENCE_NOTSET, \
131130
.py_recursion_limit = Py_DEFAULT_RECURSION_LIMIT, \
132131
.context_ver = 1, \
133132
}

Modules/_threadmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
12031203
if (boot == NULL) {
12041204
return PyErr_NoMemory();
12051205
}
1206-
boot->tstate = _PyThreadState_New(interp, _PyThreadState_WHENCE_THREADING);
1206+
boot->tstate = _PyThreadState_New(interp);
12071207
if (boot->tstate == NULL) {
12081208
PyMem_RawFree(boot);
12091209
if (!PyErr_Occurred()) {

Modules/_xxsubinterpretersmodule.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ _run_script_in_interpreter(PyObject *mod, PyInterpreterState *interp,
476476
PyThreadState *tstate = NULL;
477477
if (interp != PyInterpreterState_Get()) {
478478
tstate = PyThreadState_New(interp);
479-
tstate->_whence = _PyThreadState_WHENCE_EXEC;
480479
// XXX Possible GILState issues?
481480
save_tstate = PyThreadState_Swap(tstate);
482481
}
@@ -604,7 +603,6 @@ interp_destroy(PyObject *self, PyObject *args, PyObject *kwds)
604603

605604
// Destroy the interpreter.
606605
PyThreadState *tstate = PyThreadState_New(interp);
607-
tstate->_whence = _PyThreadState_WHENCE_INTERP;
608606
// XXX Possible GILState issues?
609607
PyThreadState *save_tstate = PyThreadState_Swap(tstate);
610608
Py_EndInterpreter(tstate);

Python/pylifecycle.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,7 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
650650
return status;
651651
}
652652

653-
PyThreadState *tstate = _PyThreadState_New(interp,
654-
_PyThreadState_WHENCE_INTERP);
653+
PyThreadState *tstate = _PyThreadState_New(interp);
655654
if (tstate == NULL) {
656655
return _PyStatus_ERR("can't make first thread");
657656
}
@@ -2052,8 +2051,7 @@ new_interpreter(PyThreadState **tstate_p, const PyInterpreterConfig *config)
20522051
return _PyStatus_OK();
20532052
}
20542053

2055-
PyThreadState *tstate = _PyThreadState_New(interp,
2056-
_PyThreadState_WHENCE_INTERP);
2054+
PyThreadState *tstate = _PyThreadState_New(interp);
20572055
if (tstate == NULL) {
20582056
PyInterpreterState_Delete(interp);
20592057
*tstate_p = NULL;

Python/pystate.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,6 @@ _PyInterpreterState_SetNotRunningMain(PyInterpreterState *interp)
10771077
// thread, so it was set as threading._main_thread. (See gh-75698.)
10781078
// The thread has finished running the Python program so we mark
10791079
// the thread object as finished.
1080-
assert(tstate->_whence != _PyThreadState_WHENCE_THREADING);
10811080
tstate->on_delete(tstate->on_delete_data);
10821081
tstate->on_delete = NULL;
10831082
tstate->on_delete_data = NULL;
@@ -1163,8 +1162,7 @@ _PyInterpreterState_IDDecref(PyInterpreterState *interp)
11631162
PyThread_release_lock(interp->id_mutex);
11641163

11651164
if (refcount == 0 && interp->requires_idref) {
1166-
PyThreadState *tstate = _PyThreadState_New(interp,
1167-
_PyThreadState_WHENCE_INTERP);
1165+
PyThreadState *tstate = _PyThreadState_New(interp);
11681166
_PyThreadState_Bind(tstate);
11691167

11701168
// XXX Possible GILState issues?
@@ -1342,7 +1340,7 @@ free_threadstate(PyThreadState *tstate)
13421340

13431341
static void
13441342
init_threadstate(PyThreadState *tstate,
1345-
PyInterpreterState *interp, uint64_t id, int whence)
1343+
PyInterpreterState *interp, uint64_t id)
13461344
{
13471345
if (tstate->_status.initialized) {
13481346
Py_FatalError("thread state already initialized");
@@ -1355,10 +1353,6 @@ init_threadstate(PyThreadState *tstate,
13551353
assert(tstate->next == NULL);
13561354
assert(tstate->prev == NULL);
13571355

1358-
assert(tstate->_whence == _PyThreadState_WHENCE_NOTSET);
1359-
assert(whence >= 0 && whence <= _PyThreadState_WHENCE_EXEC);
1360-
tstate->_whence = whence;
1361-
13621356
assert(id > 0);
13631357
tstate->id = id;
13641358

@@ -1398,7 +1392,7 @@ add_threadstate(PyInterpreterState *interp, PyThreadState *tstate,
13981392
}
13991393

14001394
static PyThreadState *
1401-
new_threadstate(PyInterpreterState *interp, int whence)
1395+
new_threadstate(PyInterpreterState *interp)
14021396
{
14031397
PyThreadState *tstate;
14041398
_PyRuntimeState *runtime = interp->runtime;
@@ -1437,7 +1431,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
14371431
sizeof(*tstate));
14381432
}
14391433

1440-
init_threadstate(tstate, interp, id, whence);
1434+
init_threadstate(tstate, interp, id);
14411435
add_threadstate(interp, tstate, old_head);
14421436

14431437
HEAD_UNLOCK(runtime);
@@ -1451,8 +1445,7 @@ new_threadstate(PyInterpreterState *interp, int whence)
14511445
PyThreadState *
14521446
PyThreadState_New(PyInterpreterState *interp)
14531447
{
1454-
PyThreadState *tstate = new_threadstate(interp,
1455-
_PyThreadState_WHENCE_UNKNOWN);
1448+
PyThreadState *tstate = new_threadstate(interp);
14561449
if (tstate) {
14571450
bind_tstate(tstate);
14581451
// This makes sure there's a gilstate tstate bound
@@ -1466,16 +1459,16 @@ PyThreadState_New(PyInterpreterState *interp)
14661459

14671460
// This must be followed by a call to _PyThreadState_Bind();
14681461
PyThreadState *
1469-
_PyThreadState_New(PyInterpreterState *interp, int whence)
1462+
_PyThreadState_New(PyInterpreterState *interp)
14701463
{
1471-
return new_threadstate(interp, whence);
1464+
return new_threadstate(interp);
14721465
}
14731466

14741467
// We keep this for stable ABI compabibility.
14751468
PyThreadState *
14761469
_PyThreadState_Prealloc(PyInterpreterState *interp)
14771470
{
1478-
return _PyThreadState_New(interp, _PyThreadState_WHENCE_UNKNOWN);
1471+
return _PyThreadState_New(interp);
14791472
}
14801473

14811474
// We keep this around for (accidental) stable ABI compatibility.
@@ -2239,8 +2232,7 @@ PyGILState_Ensure(void)
22392232
if (tcur == NULL) {
22402233
/* Create a new Python thread state for this thread */
22412234
// XXX Use PyInterpreterState_EnsureThreadState()?
2242-
tcur = new_threadstate(runtime->gilstate.autoInterpreterState,
2243-
_PyThreadState_WHENCE_GILSTATE);
2235+
tcur = new_threadstate(runtime->gilstate.autoInterpreterState);
22442236
if (tcur == NULL) {
22452237
Py_FatalError("Couldn't create thread-state for new thread");
22462238
}

0 commit comments

Comments
 (0)