summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2015-07-05 00:58:11 (GMT)
committerBenjamin Peterson <benjamin@python.org>2015-07-05 00:58:11 (GMT)
commit2a48a6eb335e496220aa75f6daae5b56e231b8e4 (patch)
treea64d419a7608dac39b456a7e98f99e4ae248b945 /Objects
parent09e60588389710232030a39b1ae9ba99542ba602 (diff)
parenta82f77fb00ca3bd3eb27a6a5d77a19eadcf0ba31 (diff)
downloadcpython-2a48a6eb335e496220aa75f6daae5b56e231b8e4.zip
cpython-2a48a6eb335e496220aa75f6daae5b56e231b8e4.tar.gz
cpython-2a48a6eb335e496220aa75f6daae5b56e231b8e4.tar.bz2
merge 3.3 (#24407)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/dictobject.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index bab6242..a494d6b 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1973,20 +1973,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;
+ }
}
}
}