Skip to content

Commit

Permalink
pythonGH-95818: Skip incomplete frames in PyThreadState_GetFrame (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
markshannon authored Aug 11, 2022
1 parent 23a757f commit 1b46d11
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Lib/test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ def inner():
r"^<frame at 0x[0-9a-fA-F]+, file %s, line %d, code inner>$"
% (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__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip over incomplete frames in :c:func:`PyThreadState_GetFrame`.
8 changes: 6 additions & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1255,10 +1255,14 @@ PyFrameObject*
PyThreadState_GetFrame(PyThreadState *tstate)
{
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;
}
PyFrameObject *frame = _PyFrame_GetFrameObject(tstate->cframe->current_frame);
PyFrameObject *frame = _PyFrame_GetFrameObject(f);
if (frame == NULL) {
PyErr_Clear();
}
Expand Down

0 comments on commit 1b46d11

Please sign in to comment.