diff options
author | Larry Hastings <larry@hastings.org> | 2015-07-05 10:31:09 -0700 |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2015-07-05 10:31:09 -0700 |
commit | ab30353adbef3a3fdd54fb30856af8ff94f2c108 (patch) | |
tree | 4c330aa36e455a7a6223e1488bc7a7a1b384b538 /Objects | |
parent | b34db6ad9b3332c3101bcf7e020e90583693db20 (diff) | |
parent | 95f9dd5e72d6a72db0ad7438b65990cba30cf36b (diff) | |
download | cpython-git-ab30353adbef3a3fdd54fb30856af8ff94f2c108.tar.gz |
Merge with ongoing work in 3.5 branch.
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 3791d5b398..5a7de9e539 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; + } } } } |