Skip to content

Commit 3072338

Browse files
authored
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.
1 parent 89a2209 commit 3072338

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Modules/_tracemalloc.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,8 @@ traceback_get_frames(traceback_t *traceback)
445445
return;
446446
}
447447

448-
for (pyframe = tstate->frame; pyframe != NULL; pyframe = pyframe->f_back) {
448+
pyframe = PyThreadState_GetFrame(tstate);
449+
for (; pyframe != NULL; pyframe = pyframe->f_back) {
449450
if (traceback->nframe < _Py_tracemalloc_config.max_nframe) {
450451
tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]);
451452
assert(traceback->frames[traceback->nframe].filename != NULL);

Modules/_xxsubinterpretersmodule.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ _is_running(PyInterpreterState *interp)
18301830
"interpreter has more than one thread");
18311831
return -1;
18321832
}
1833-
PyFrameObject *frame = tstate->frame;
1833+
PyFrameObject *frame = PyThreadState_GetFrame(tstate);
18341834
if (frame == NULL) {
18351835
if (PyErr_Occurred() != NULL) {
18361836
return -1;
@@ -2004,15 +2004,16 @@ interp_create(PyObject *self, PyObject *args)
20042004
PyErr_SetString(PyExc_RuntimeError, "interpreter creation failed");
20052005
return NULL;
20062006
}
2007-
PyObject *idobj = _PyInterpreterState_GetIDObject(tstate->interp);
2007+
PyInterpreterState *interp = PyThreadState_GetInterpreter(tstate);
2008+
PyObject *idobj = _PyInterpreterState_GetIDObject(interp);
20082009
if (idobj == NULL) {
20092010
// XXX Possible GILState issues?
20102011
save_tstate = PyThreadState_Swap(tstate);
20112012
Py_EndInterpreter(tstate);
20122013
PyThreadState_Swap(save_tstate);
20132014
return NULL;
20142015
}
2015-
_PyInterpreterState_RequireIDRef(tstate->interp, 1);
2016+
_PyInterpreterState_RequireIDRef(interp, 1);
20162017
return idobj;
20172018
}
20182019

0 commit comments

Comments
 (0)