]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix _PyDict_Pop() on pending key
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Sep 2016 14:56:38 +0000 (16:56 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 13 Sep 2016 14:56:38 +0000 (16:56 +0200)
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.

Lib/test/test_dict.py
Misc/NEWS
Objects/dictobject.c

index fb954c813257c463b9fd4c58d9792bea83e1c0f2..ed66ddbcb4ec9660c19dc1ade83c37202fad8100 100644 (file)
@@ -891,6 +891,15 @@ class DictTest(unittest.TestCase):
         self.assertEqual(list(a), ['x', 'z', 'y'])
         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()"""
index 34c3748ee4f5b14ab1337119f6e1fd847b60e3ae..57f1b5393859d09061a45828c1cc1bf2934988a9 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2
 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
 -------
 
index bb5962a1a5e2f7e31894b38bdd7e0acac0246b9f..06c54b566550a7b0cba6bae4fe2a56ca76834f8a 100644 (file)
@@ -1721,7 +1721,7 @@ _PyDict_Pop(PyDictObject *mp, PyObject *key, PyObject *deflt)
     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;