diff options
author | Mark Shannon <mark@hotpy.org> | 2022-09-06 16:37:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-06 16:37:47 (GMT) |
commit | 95e271b2266b8f2e7b60ede86ccf3ede4a7f83eb (patch) | |
tree | 1e0f787da14d97d825b8349b9871caaf12d6f573 | |
parent | f0d9136c69b4ed32bfb3096f926da098623a7072 (diff) | |
download | cpython-95e271b2266b8f2e7b60ede86ccf3ede4a7f83eb.zip cpython-95e271b2266b8f2e7b60ede86ccf3ede4a7f83eb.tar.gz cpython-95e271b2266b8f2e7b60ede86ccf3ede4a7f83eb.tar.bz2 |
GH-96612: Skip incomplete frames in tracemalloc traces. (GH-96613)
-rw-r--r-- | Lib/test/test_tracemalloc.py | 14 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2022-09-06-14-26-36.gh-issue-96612.P4ZbeY.rst | 1 | ||||
-rw-r--r-- | Modules/_tracemalloc.c | 11 |
3 files changed, 23 insertions, 3 deletions
diff --git a/Lib/test/test_tracemalloc.py b/Lib/test/test_tracemalloc.py index d2a5ede..94bcee3 100644 --- a/Lib/test/test_tracemalloc.py +++ b/Lib/test/test_tracemalloc.py @@ -360,6 +360,20 @@ class TestTracemallocEnabled(unittest.TestCase): else: support.wait_process(pid, exitcode=0) + def test_no_incomplete_frames(self): + tracemalloc.stop() + tracemalloc.start(8) + + def f(x): + def g(): + return x + return g + + obj = f(0).__closure__[0] + traceback = tracemalloc.get_object_traceback(obj) + self.assertIn("test_tracemalloc", traceback[-1].filename) + self.assertNotIn("test_tracemalloc", traceback[-2].filename) + class TestSnapshot(unittest.TestCase): maxDiff = 4000 diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-09-06-14-26-36.gh-issue-96612.P4ZbeY.rst b/Misc/NEWS.d/next/Core and Builtins/2022-09-06-14-26-36.gh-issue-96612.P4ZbeY.rst new file mode 100644 index 0000000..52e9270 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-09-06-14-26-36.gh-issue-96612.P4ZbeY.rst @@ -0,0 +1 @@ +Make sure that incomplete frames do not show up in tracemalloc traces. diff --git a/Modules/_tracemalloc.c b/Modules/_tracemalloc.c index ae09869..44a1f7b 100644 --- a/Modules/_tracemalloc.c +++ b/Modules/_tracemalloc.c @@ -400,7 +400,13 @@ traceback_get_frames(traceback_t *traceback) } _PyInterpreterFrame *pyframe = tstate->cframe->current_frame; - for (; pyframe != NULL;) { + for (;;) { + while (pyframe && _PyFrame_IsIncomplete(pyframe)) { + pyframe = pyframe->previous; + } + if (pyframe == NULL) { + break; + } if (traceback->nframe < _Py_tracemalloc_config.max_nframe) { tracemalloc_get_frame(pyframe, &traceback->frames[traceback->nframe]); assert(traceback->frames[traceback->nframe].filename != NULL); @@ -410,8 +416,7 @@ traceback_get_frames(traceback_t *traceback) traceback->total_nframe++; } - _PyInterpreterFrame *back = pyframe->previous; - pyframe = back; + pyframe = pyframe->previous; } } |