diff options
author | Éric Araujo <merwok@netwok.org> | 2011-03-23 01:08:07 (GMT) |
---|---|---|
committer | Éric Araujo <merwok@netwok.org> | 2011-03-23 01:08:07 (GMT) |
commit | 48049911d6ff4f3caebc09a28c0a94e0c7ad8842 (patch) | |
tree | fc6fadcb04b046e45b552af2b76d5169200bb234 /Lib | |
parent | c706dbfa67236eccf389b7c3cea029baf7eab8b2 (diff) | |
download | cpython-48049911d6ff4f3caebc09a28c0a94e0c7ad8842.zip cpython-48049911d6ff4f3caebc09a28c0a94e0c7ad8842.tar.gz cpython-48049911d6ff4f3caebc09a28c0a94e0c7ad8842.tar.bz2 |
Fix obscure set crashers (#8420). Backport of d56b3cafb1e6, reviewed by Raymond.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_set.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index fdbfe19..99d5c70 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -1660,6 +1660,39 @@ class TestVariousIteratorArgs(unittest.TestCase): self.assertRaises(TypeError, getattr(set('january'), methname), N(data)) self.assertRaises(ZeroDivisionError, getattr(set('january'), methname), E(data)) +class bad_eq: + def __eq__(self, other): + if be_bad: + set2.clear() + raise ZeroDivisionError + return self is other + def __hash__(self): + return 0 + +class bad_dict_clear: + def __eq__(self, other): + if be_bad: + dict2.clear() + return self is other + def __hash__(self): + return 0 + +class TestWeirdBugs(unittest.TestCase): + def test_8420_set_merge(self): + # This used to segfault + global be_bad, set2, dict2 + be_bad = False + set1 = {bad_eq()} + set2 = {bad_eq() for i in range(75)} + be_bad = True + self.assertRaises(ZeroDivisionError, set1.update, set2) + + be_bad = False + set1 = {bad_dict_clear()} + dict2 = {bad_dict_clear(): None} + be_bad = True + set1.symmetric_difference_update(dict2) + # Application tests (based on David Eppstein's graph recipes ==================================== def powerset(U): @@ -1804,6 +1837,7 @@ def test_main(verbose=None): TestIdentities, TestVariousIteratorArgs, TestGraphs, + TestWeirdBugs, ) support.run_unittest(*test_classes) |