bpo-39947: Use PyThreadState_GetFrame() (GH-19159)

_tracemalloc.c and _xxsubinterpretersmodule.c use
PyThreadState_GetFrame() and PyThreadState_GetInterpreter() to no
longer depend on the PyThreadState structure.
This commit is contained in:
Victor Stinner 2020-03-25 19:52:02 +01:00 committed by GitHub
parent 89a2209ae6
commit 3072338642
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -445,7 +445,8 @@ traceback_get_frames(traceback_t *traceback)
return;
}
for (pyframe = tstate->frame; pyframe != NULL; pyframe = pyframe->f_back) {
pyframe = PyThreadState_GetFrame(tstate);
for (; pyframe != NULL; pyframe = pyframe->f_back) {
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
assert(traceback->frames[traceback->nframe].filename != NULL);

View File

@ -1830,7 +1830,7 @@ _is_running(PyInterpreterState *interp)
"interpreter has more than one thread");
return -1;
}
PyFrameObject *frame = tstate->frame;
PyFrameObject *frame = PyThreadState_GetFrame(tstate);
if (frame == NULL) {
if (PyErr_Occurred() != NULL) {
return -1;
@ -2004,7 +2004,8 @@ interp_create(PyObject *self, PyObject *args)
PyErr_SetString(PyExc_RuntimeError, "interpreter creation failed");
return NULL;
}
PyObject *idobj = _PyInterpreterState_GetIDObject(tstate->interp);
PyInterpreterState *interp = PyThreadState_GetInterpreter(tstate);
PyObject *idobj = _PyInterpreterState_GetIDObject(interp);
if (idobj == NULL) {
// XXX Possible GILState issues?
save_tstate = PyThreadState_Swap(tstate);
@ -2012,7 +2013,7 @@ interp_create(PyObject *self, PyObject *args)
PyThreadState_Swap(save_tstate);
return NULL;
}
_PyInterpreterState_RequireIDRef(tstate->interp, 1);
_PyInterpreterState_RequireIDRef(interp, 1);
return idobj;
}