bpo-45953: Statically initialize all the PyThreadState fields we can. (gh-30590)

https://bugs.python.org/issue45953
This commit is contained in:
Eric Snow 2022-01-13 17:09:24 -07:00 committed by GitHub
parent d4e64cd4b0
commit 324908ba93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 24 deletions

View file

@ -737,10 +737,6 @@ Py_MakePendingCalls(void)
/* The interpreter's recursion limit */
#ifndef Py_DEFAULT_RECURSION_LIMIT
# define Py_DEFAULT_RECURSION_LIMIT 1000
#endif
void
_PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
{

View file

@ -775,21 +775,19 @@ init_threadstate(PyThreadState *tstate,
next->prev = tstate;
}
tstate->next = next;
tstate->prev = NULL;
assert(tstate->prev == NULL);
tstate->thread_id = PyThread_get_thread_ident();
#ifdef PY_HAVE_THREAD_NATIVE_ID
tstate->native_thread_id = PyThread_get_thread_native_id();
#endif
tstate->context_ver = 1;
tstate->recursion_limit = interp->ceval.recursion_limit,
tstate->recursion_remaining = interp->ceval.recursion_limit,
tstate->exc_info = &tstate->exc_state;
tstate->exc_info = &tstate->_exc_state;
tstate->cframe = &tstate->root_cframe;
tstate->cframe = &tstate->_root_cframe;
tstate->datastack_chunk = NULL;
tstate->datastack_top = NULL;
tstate->datastack_limit = NULL;
@ -1027,10 +1025,10 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->curexc_value);
Py_CLEAR(tstate->curexc_traceback);
Py_CLEAR(tstate->exc_state.exc_value);
Py_CLEAR(tstate->_exc_state.exc_value);
/* The stack of exception states should contain just this thread. */
if (verbose && tstate->exc_info != &tstate->exc_state) {
if (verbose && tstate->exc_info != &tstate->_exc_state) {
fprintf(stderr,
"PyThreadState_Clear: warning: thread still has a generator\n");
}