diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2023-03-05 11:20:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-05 11:20:41 (GMT) |
commit | d4a04e55d8bd8eaa307f3e4aa8b443301a0d996a (patch) | |
tree | ebf345b79cb8ef303c61a6d23624454311e8ffc6 /Lib/test | |
parent | d4992c7315c1b92a73eec30407ed0cf3b673194a (diff) | |
download | cpython-d4a04e55d8bd8eaa307f3e4aa8b443301a0d996a.zip cpython-d4a04e55d8bd8eaa307f3e4aa8b443301a0d996a.tar.gz cpython-d4a04e55d8bd8eaa307f3e4aa8b443301a0d996a.tar.bz2 |
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 66aa78cbe604a7c5731f074b869f92174a8e3b64)
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_builtin.py | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index aabf0ab..f31ab72 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -799,6 +799,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, sys, 1) |