mirror of https://github.com/python/cpython.git
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.
This commit is contained in:
parent
9926480b6a
commit
d0ad11f6b4
|
@ -891,6 +891,15 @@ def test_splittable_pop(self):
|
||||||
self.assertEqual(list(a), ['x', 'z', 'y'])
|
self.assertEqual(list(a), ['x', 'z', 'y'])
|
||||||
self.assertEqual(list(b), ['x', 'y', 'z'])
|
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
|
@support.cpython_only
|
||||||
def test_splittable_popitem(self):
|
def test_splittable_popitem(self):
|
||||||
"""split table must be combined when d.popitem()"""
|
"""split table must be combined when d.popitem()"""
|
||||||
|
|
|
@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
|
||||||
Core and Builtins
|
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
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
|
@ -1721,7 +1721,7 @@ _PyDict_Pop(PyDictObject *mp, PyObject *key, PyObject *deflt)
|
||||||
ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr, &hashpos);
|
ix = (mp->ma_keys->dk_lookup)(mp, key, hash, &value_addr, &hashpos);
|
||||||
if (ix == DKIX_ERROR)
|
if (ix == DKIX_ERROR)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (ix == DKIX_EMPTY) {
|
if (ix == DKIX_EMPTY || *value_addr == NULL) {
|
||||||
if (deflt) {
|
if (deflt) {
|
||||||
Py_INCREF(deflt);
|
Py_INCREF(deflt);
|
||||||
return deflt;
|
return deflt;
|
||||||
|
|
Loading…
Reference in New Issue