(original) (raw)

changeset: 103763:dc627ef9020f branch: 3.6 parent: 103761:3c7456e28777 user: Victor Stinner victor.stinner@gmail.com date: Tue Sep 13 16:56:38 2016 +0200 files: Lib/test/test_dict.py Misc/NEWS Objects/dictobject.c description: Fix _PyDict_Pop() on pending key Issue #28120: Fix dict.pop() for splitted dictionary when trying to remove a "pending key" (Not yet inserted in split-table). Patch by Xiang Zhang. diff -r 3c7456e28777 -r dc627ef9020f Lib/test/test_dict.py --- a/Lib/test/test_dict.py Tue Sep 13 09:38:29 2016 +0200 +++ b/Lib/test/test_dict.py Tue Sep 13 16:56:38 2016 +0200 @@ -892,6 +892,15 @@ self.assertEqual(list(b), ['x', 'y', 'z']) @support.cpython_only + def test_splittable_pop_pending(self): + """pop a pending key in a splitted table should not crash""" + a, b = self.make_shared_key_dict(2) + + a['a'] = 4 + with self.assertRaises(KeyError): + b.pop('a') + + @support.cpython_only def test_splittable_popitem(self): """split table must be combined when d.popitem()""" a, b = self.make_shared_key_dict(2) diff -r 3c7456e28777 -r dc627ef9020f Misc/NEWS --- a/Misc/NEWS Tue Sep 13 09:38:29 2016 +0200 +++ b/Misc/NEWS Tue Sep 13 16:56:38 2016 +0200 @@ -10,6 +10,9 @@ Core and Builtins ----------------- +- Issue #28120: Fix dict.pop() for splitted dictionary when trying to remove a + "pending key" (Not yet inserted in split-table). Patch by Xiang Zhang. + Library ------- diff -r 3c7456e28777 -r dc627ef9020f Objects/dictobject.c --- a/Objects/dictobject.c Tue Sep 13 09:38:29 2016 +0200 +++ b/Objects/dictobject.c Tue Sep 13 16:56:38 2016 +0200 @@ -1721,7 +1721,7 @@ ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr, &hashpos); if (ix == DKIX_ERROR) return NULL; - if (ix == DKIX_EMPTY) { + if (ix == DKIX_EMPTY || *value_addr == NULL) { if (deflt) { Py_INCREF(deflt); return deflt; /victor.stinner@gmail.com