summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-10-17 22:35:00 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-10-17 22:35:00 (GMT)
commitd6967320256a65b847cfc64173d12bf818171db5 (patch)
treeda653da4d00d3b839e078cd39ac146e597c265b6 /Lib
parentbaa6d3a01f9716e96ccc8126c863a8e5916e910c (diff)
downloadcpython-d6967320256a65b847cfc64173d12bf818171db5.zip
cpython-d6967320256a65b847cfc64173d12bf818171db5.tar.gz
cpython-d6967320256a65b847cfc64173d12bf818171db5.tar.bz2
Issue #22653: Fix an assertion failure in debug mode when doing a reentrant dict insertion in debug mode.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_dict.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py
index a388959..98d8a3b 100644
--- a/Lib/test/test_dict.py
+++ b/Lib/test/test_dict.py
@@ -906,6 +906,35 @@ class DictTest(unittest.TestCase):
f.a = 'a'
self.assertEqual(f.__dict__, {1:1, 'a':'a'})
+ def check_reentrant_insertion(self, mutate):
+ # This object will trigger mutation of the dict when replaced
+ # by another value. Note this relies on refcounting: the test
+ # won't achieve its purpose on fully-GCed Python implementations.
+ class Mutating:
+ def __del__(self):
+ mutate(d)
+
+ d = {k: Mutating() for k in 'abcdefghijklmnopqr'}
+ for k in list(d):
+ d[k] = k
+
+ def test_reentrant_insertion(self):
+ # Reentrant insertion shouldn't crash (see issue #22653)
+ def mutate(d):
+ d['b'] = 5
+ self.check_reentrant_insertion(mutate)
+
+ def mutate(d):
+ d.update(self.__dict__)
+ d.clear()
+ self.check_reentrant_insertion(mutate)
+
+ def mutate(d):
+ while d:
+ d.popitem()
+ self.check_reentrant_insertion(mutate)
+
+
from test import mapping_tests
class GeneralMappingTests(mapping_tests.BasicTestMappingProtocol):