[Python-checkins] GH-95818: Skip incomplete frames in `PyThreadState_GetFrame` (GH-95886) (#95890)
pablogsal
webhook-mailer at python.org
Fri Aug 12 14:40:54 EDT 2022
https://github.com/python/cpython/commit/6fc90c11835f1af869a47724ab9742535b73fe7b
commit: 6fc90c11835f1af869a47724ab9742535b73fe7b
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2022-08-12T19:40:49+01:00
summary:
GH-95818: Skip incomplete frames in `PyThreadState_GetFrame` (GH-95886) (#95890)
(cherry picked from commit 1b46d118e6e72daa64b98cafddb406c68b419efa)
Co-authored-by: Mark Shannon <mark at hotpy.org>
Co-authored-by: Mark Shannon <mark at hotpy.org>
files:
A Misc/NEWS.d/next/Core and Builtins/2022-08-11-11-01-56.gh-issue-95818.iClLdl.rst
M Lib/test/test_frame.py
M Python/pystate.c
diff --git a/Lib/test/test_frame.py b/Lib/test/test_frame.py
index a715e725a7e4..9fab17684eec 100644
--- a/Lib/test/test_frame.py
+++ b/Lib/test/test_frame.py
@@ -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()
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-08-11-11-01-56.gh-issue-95818.iClLdl.rst b/Misc/NEWS.d/next/Core and Builtins/2022-08-11-11-01-56.gh-issue-95818.iClLdl.rst
new file mode 100644
index 000000000000..1e243f5614f1
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-08-11-11-01-56.gh-issue-95818.iClLdl.rst
@@ -0,0 +1 @@
+Skip over incomplete frames in :c:func:`PyThreadState_GetFrame`.
diff --git a/Python/pystate.c b/Python/pystate.c
index df56c0530f05..2e4585688ea8 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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();
}
More information about the Python-checkins
mailing list