mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
GH-95818: Skip incomplete frames in PyThreadState_GetFrame
(GH-95886) (#95890)
(cherry picked from commit 1b46d118e6
)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Mark Shannon <mark@hotpy.org>
This commit is contained in:
parent
4abf84602f
commit
6fc90c1183
3 changed files with 29 additions and 2 deletions
|
@ -235,6 +235,28 @@ class ReprTest(unittest.TestCase):
|
||||||
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$"
|
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$"
|
||||||
% (file_repr, offset + 5))
|
% (file_repr, offset + 5))
|
||||||
|
|
||||||
|
class TestIncompleteFrameAreInvisible(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_issue95818(self):
|
||||||
|
#See GH-95818 for details
|
||||||
|
import gc
|
||||||
|
self.addCleanup(gc.set_threshold, *gc.get_threshold())
|
||||||
|
|
||||||
|
gc.set_threshold(1,1,1)
|
||||||
|
class GCHello:
|
||||||
|
def __del__(self):
|
||||||
|
print("Destroyed from gc")
|
||||||
|
|
||||||
|
def gen():
|
||||||
|
yield
|
||||||
|
|
||||||
|
fd = open(__file__)
|
||||||
|
l = [fd, GCHello()]
|
||||||
|
l.append(l)
|
||||||
|
del fd
|
||||||
|
del l
|
||||||
|
gen()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Skip over incomplete frames in :c:func:`PyThreadState_GetFrame`.
|
|
@ -1255,10 +1255,14 @@ PyFrameObject*
|
||||||
PyThreadState_GetFrame(PyThreadState *tstate)
|
PyThreadState_GetFrame(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
assert(tstate != NULL);
|
assert(tstate != NULL);
|
||||||
if (tstate->cframe->current_frame == NULL) {
|
_PyInterpreterFrame *f = tstate->cframe->current_frame;
|
||||||
|
while (f && _PyFrame_IsIncomplete(f)) {
|
||||||
|
f = f->previous;
|
||||||
|
}
|
||||||
|
if (f == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyFrameObject *frame = _PyFrame_GetFrameObject(tstate->cframe->current_frame);
|
PyFrameObject *frame = _PyFrame_GetFrameObject(f);
|
||||||
if (frame == NULL) {
|
if (frame == NULL) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue