mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-102356: Add thrashcan macros to filter object dealloc (GH-102426)
Add thrashcan macros to the deallocator of the filter objects to protect against deeply nested destruction of chains of nested filters.
(cherry picked from commit 66aa78cbe6
)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
This commit is contained in:
parent
caff048cb3
commit
63fd954100
4 changed files with 15 additions and 0 deletions
|
@ -919,6 +919,16 @@ class BuiltinTest(unittest.TestCase):
|
|||
f2 = filter(filter_char, "abcdeabcde")
|
||||
self.check_iter_pickle(f1, list(f2), proto)
|
||||
|
||||
def test_filter_dealloc(self):
|
||||
# Tests recursive deallocation of nested filter objects using the
|
||||
# thrashcan mechanism. See gh-102356 for more details.
|
||||
max_iters = 1000000
|
||||
i = filter(bool, range(max_iters))
|
||||
for _ in range(max_iters):
|
||||
i = filter(bool, i)
|
||||
del i
|
||||
gc.collect()
|
||||
|
||||
def test_getattr(self):
|
||||
self.assertTrue(getattr(sys, 'stdout') is sys.stdout)
|
||||
self.assertRaises(TypeError, getattr)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue