diff options
author | Victor Stinner <vstinner@python.org> | 2020-04-29 01:01:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 01:01:43 (GMT) |
commit | 4386b9045e5fe1151e65c2816264b5710000eb9f (patch) | |
tree | c1bcaffac32a12c8e8f52c1e621d18665b06ac6b /Modules | |
parent | 37af21b667a9f41437b5b8e451497d7725016df5 (diff) | |
download | cpython-4386b9045e5fe1151e65c2816264b5710000eb9f.zip cpython-4386b9045e5fe1151e65c2816264b5710000eb9f.tar.gz cpython-4386b9045e5fe1151e65c2816264b5710000eb9f.tar.bz2 |
bpo-40429: PyThreadState_GetFrame() returns a strong ref (GH-19781)
The PyThreadState_GetFrame() function now returns a strong reference
to the frame.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_tracemalloc.c | 8 | ||||
-rw-r--r-- | Modules/_xxsubinterpretersmodule.c | 11 |
2 files changed, 10 insertions, 9 deletions
diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index 24628a9..6f28f7f 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -425,10 +425,7 @@ traceback_hash(traceback_t *traceback) static void traceback_get_frames(traceback_t *traceback) { - PyThreadState *tstate; - PyFrameObject *pyframe; - - tstate = PyGILState_GetThisThreadState(); + PyThreadState *tstate = PyGILState_GetThisThreadState(); if (tstate == NULL) { #ifdef TRACE_DEBUG tracemalloc_error("failed to get the current thread state"); @@ -436,7 +433,8 @@ traceback_get_frames(traceback_t *traceback) return; } - pyframe = PyThreadState_GetFrame(tstate); + PyFrameObject *pyframe = PyThreadState_GetFrame(tstate); + Py_XDECREF(pyframe); // use a borrowed reference for (; pyframe != NULL; pyframe = pyframe->f_back) { if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); diff --git a/Modules/_xxsubinterpretersmodule.c b/Modules/_xxsubinterpretersmodule.c index e618930..15e8055 100644 --- a/Modules/_xxsubinterpretersmodule.c +++ b/Modules/_xxsubinterpretersmodule.c @@ -1840,14 +1840,17 @@ _is_running(PyInterpreterState *interp) "interpreter has more than one thread"); return -1; } + + assert(!PyErr_Occurred()); PyFrameObject *frame = PyThreadState_GetFrame(tstate); if (frame == NULL) { - if (PyErr_Occurred() != NULL) { - return -1; - } return 0; } - return (int)(frame->f_executing); + + int executing = (int)(frame->f_executing); + Py_DECREF(frame); + + return executing; } static int |