diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-30 17:17:24 +0200 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-10-30 17:17:24 +0200 |
commit | 043868393969224947c03617475d31f64ea59634 (patch) | |
tree | 4ff186fcef3c3c7f6967e707ded591e2b3d6b609 /Objects/odictobject.c | |
parent | b8c5f54248369ff89575c1416a98e13e718a4aa4 (diff) | |
download | cpython-git-043868393969224947c03617475d31f64ea59634.tar.gz |
Backed out changeset 9f7505019767 (issue #27275).
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r-- | Objects/odictobject.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c index b4940e39ec..a6963d7d53 100644 --- a/Objects/odictobject.c +++ b/Objects/odictobject.c @@ -1099,13 +1099,28 @@ _odict_popkey_hash(PyObject *od, PyObject *key, PyObject *failobj, } /* Now delete the value from the dict. */ - if (node != NULL) { - value = _PyDict_GetItem_KnownHash(od, key, hash); /* borrowed */ - if (value != NULL) { - Py_INCREF(value); - if (_PyDict_DelItem_KnownHash(od, key, hash) < 0) { - Py_DECREF(value); - return NULL; + if (PyODict_CheckExact(od)) { + if (node != NULL) { + value = _PyDict_GetItem_KnownHash(od, key, hash); /* borrowed */ + if (value != NULL) { + Py_INCREF(value); + if (_PyDict_DelItem_KnownHash(od, key, hash) < 0) { + Py_DECREF(value); + return NULL; + } + } + } + } + else { + int exists = PySequence_Contains(od, key); + if (exists < 0) + return NULL; + if (exists) { + value = PyObject_GetItem(od, key); + if (value != NULL) { + if (PyObject_DelItem(od, key) == -1) { + Py_CLEAR(value); + } } } } |