Skip to content

Commit 61a0506

Browse files
committed
Add tests for filter object recursion and garbage collection handling
1 parent 21a3924 commit 61a0506

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Lib/test/test_builtin.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,22 @@ def test_filter_dealloc(self):
11321132
del i
11331133
gc.collect()
11341134

1135+
@support.skip_wasi_stack_overflow()
1136+
@support.skip_emscripten_stack_overflow()
1137+
@support.requires_resource('cpu')
1138+
def test_filter_deep_nesting_recursion_error(self):
1139+
# gh-137894: Test that deeply nested filter() iterator chains
1140+
# raise RecursionError instead of causing segmentation fault.
1141+
# This verifies that the tp_clear method prevents stack overflow
1142+
# during garbage collection of cyclic references.
1143+
i = filter(bool, range(1000000))
1144+
for _ in range(100000):
1145+
i = filter(bool, i)
1146+
1147+
# Should raise RecursionError, not segmentation fault
1148+
with self.assertRaises(RecursionError):
1149+
list(i)
1150+
11351151
def test_getattr(self):
11361152
self.assertTrue(getattr(sys, 'stdout') is sys.stdout)
11371153
self.assertRaises(TypeError, getattr)

0 commit comments

Comments
 (0)