diff options
author | Benjamin Peterson <benjamin@python.org> | 2015-07-05 00:59:50 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2015-07-05 00:59:50 (GMT) |
commit | d34c246baf7bdfb2d5dacf04b7d5fae76a20ed2c (patch) | |
tree | a78d02f247ee3437877e6611700d5ba64189bd19 /Objects | |
parent | d48fb485d9d6597b1048f6131a28cb14979349af (diff) | |
parent | e54d5321cc527d0c97a95b90b2754f6494e7b3e1 (diff) | |
download | cpython-d34c246baf7bdfb2d5dacf04b7d5fae76a20ed2c.zip cpython-d34c246baf7bdfb2d5dacf04b7d5fae76a20ed2c.tar.gz cpython-d34c246baf7bdfb2d5dacf04b7d5fae76a20ed2c.tar.bz2 |
merge 3.5 (#24407)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/dictobject.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 3791d5b..5a7de9e 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -2039,20 +2039,32 @@ PyDict_Merge(PyObject *a, PyObject *b, int override) if (dictresize(mp, (mp->ma_used + other->ma_used)*2) != 0) return -1; for (i = 0, n = DK_SIZE(other->ma_keys); i < n; i++) { - PyObject *value; + PyObject *key, *value; + Py_hash_t hash; entry = &other->ma_keys->dk_entries[i]; + key = entry->me_key; + hash = entry->me_hash; if (other->ma_values) value = other->ma_values[i]; else value = entry->me_value; - if (value != NULL && - (override || - PyDict_GetItem(a, entry->me_key) == NULL)) { - if (insertdict(mp, entry->me_key, - entry->me_hash, - value) != 0) + if (value != NULL) { + int err = 0; + Py_INCREF(key); + Py_INCREF(value); + if (override || PyDict_GetItem(a, key) == NULL) + err = insertdict(mp, key, hash, value); + Py_DECREF(value); + Py_DECREF(key); + if (err != 0) + return -1; + + if (n != DK_SIZE(other->ma_keys)) { + PyErr_SetString(PyExc_RuntimeError, + "dict mutated during update"); return -1; + } } } } |