diff options
author | INADA Naoki <songofacandy@gmail.com> | 2016-12-20 00:54:24 (GMT) |
---|---|---|
committer | INADA Naoki <songofacandy@gmail.com> | 2016-12-20 00:54:24 (GMT) |
commit | 6165d55f1398ddf1cbd21e237129af7116a1fa73 (patch) | |
tree | 7cd85f7eda77b7fdfe55dd2e6e08b4f03b5ce915 /Lib | |
parent | 270a21fda0c41ea120727140ac966a86f694eee4 (diff) | |
download | cpython-6165d55f1398ddf1cbd21e237129af7116a1fa73.zip cpython-6165d55f1398ddf1cbd21e237129af7116a1fa73.tar.gz cpython-6165d55f1398ddf1cbd21e237129af7116a1fa73.tar.bz2 |
Issue #28147: Fix a memory leak in split-table dictionaries
setattr() must not convert combined table into split table.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_dict.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index 6d68e76..b85d333 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -836,6 +836,24 @@ class DictTest(unittest.TestCase): pass self._tracked(MyDict()) + @support.cpython_only + def test_splittable_setattr_after_pop(self): + """setattr must not convert combined table into split table""" + # Issue 28147 + import _testcapi + + class C: + pass + a = C() + a.a = 2 + self.assertTrue(_testcapi.dict_hassplittable(a.__dict__)) + # dict.popitem() convert it to combined table + a.__dict__.popitem() + self.assertFalse(_testcapi.dict_hassplittable(a.__dict__)) + # But C should not convert a.__dict__ to split table again. + a.a = 3 + self.assertFalse(_testcapi.dict_hassplittable(a.__dict__)) + def test_iterator_pickling(self): for proto in range(pickle.HIGHEST_PROTOCOL + 1): data = {1:"a", 2:"b", 3:"c"} |