File tree 3 files changed +23
-3
lines changed
Misc/NEWS.d/next/Core and Builtins 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -360,6 +360,20 @@ def test_fork(self):
360
360
else :
361
361
support .wait_process (pid , exitcode = 0 )
362
362
363
+ def test_no_incomplete_frames (self ):
364
+ tracemalloc .stop ()
365
+ tracemalloc .start (8 )
366
+
367
+ def f (x ):
368
+ def g ():
369
+ return x
370
+ return g
371
+
372
+ obj = f (0 ).__closure__ [0 ]
373
+ traceback = tracemalloc .get_object_traceback (obj )
374
+ self .assertIn ("test_tracemalloc" , traceback [- 1 ].filename )
375
+ self .assertNotIn ("test_tracemalloc" , traceback [- 2 ].filename )
376
+
363
377
364
378
class TestSnapshot (unittest .TestCase ):
365
379
maxDiff = 4000
Original file line number Diff line number Diff line change
1
+ Make sure that incomplete frames do not show up in tracemalloc traces.
Original file line number Diff line number Diff line change @@ -400,7 +400,13 @@ traceback_get_frames(traceback_t *traceback)
400
400
}
401
401
402
402
_PyInterpreterFrame * pyframe = tstate -> cframe -> current_frame ;
403
- for (; pyframe != NULL ;) {
403
+ for (;;) {
404
+ while (pyframe && _PyFrame_IsIncomplete (pyframe )) {
405
+ pyframe = pyframe -> previous ;
406
+ }
407
+ if (pyframe == NULL ) {
408
+ break ;
409
+ }
404
410
if (traceback -> nframe < _Py_tracemalloc_config .max_nframe ) {
405
411
tracemalloc_get_frame (pyframe , & traceback -> frames [traceback -> nframe ]);
406
412
assert (traceback -> frames [traceback -> nframe ].filename != NULL );
@@ -410,8 +416,7 @@ traceback_get_frames(traceback_t *traceback)
410
416
traceback -> total_nframe ++ ;
411
417
}
412
418
413
- _PyInterpreterFrame * back = pyframe -> previous ;
414
- pyframe = back ;
419
+ pyframe = pyframe -> previous ;
415
420
}
416
421
}
417
422
You can’t perform that action at this time.
0 commit comments