diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-13 18:48:01 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-05-13 18:48:01 (GMT) |
commit | 9a2349030a706433b519ae99816fc540ecefc143 (patch) | |
tree | 8afad14bc8fa10812c97a35ef4fc1ab09521ee43 /Objects/dictobject.c | |
parent | 7feb9f42258ff72ce1d3628c5ccc261c2ca238b9 (diff) | |
download | cpython-9a2349030a706433b519ae99816fc540ecefc143.zip cpython-9a2349030a706433b519ae99816fc540ecefc143.tar.gz cpython-9a2349030a706433b519ae99816fc540ecefc143.tar.bz2 |
Issue #14417: Mutating a dict during lookup now restarts the lookup instead of raising a RuntimeError (undoes issue #14205).
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r-- | Objects/dictobject.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c index 077f3cd..fd1d46c 100644 --- a/Objects/dictobject.c +++ b/Objects/dictobject.c @@ -439,12 +439,15 @@ lookdict(PyDictObject *mp, PyObject *key, register size_t i; register size_t perturb; register PyDictKeyEntry *freeslot; - register size_t mask = DK_MASK(mp->ma_keys); - PyDictKeyEntry *ep0 = &mp->ma_keys->dk_entries[0]; + register size_t mask; + PyDictKeyEntry *ep0; register PyDictKeyEntry *ep; register int cmp; PyObject *startkey; +top: + mask = DK_MASK(mp->ma_keys); + ep0 = &mp->ma_keys->dk_entries[0]; i = (size_t)hash & mask; ep = &ep0[i]; if (ep->me_key == NULL || ep->me_key == key) { @@ -468,9 +471,8 @@ lookdict(PyDictObject *mp, PyObject *key, } } else { - PyErr_SetString(PyExc_RuntimeError, - "dictionary changed size during lookup"); - return NULL; + /* The dict was mutated, restart */ + goto top; } } freeslot = NULL; @@ -510,9 +512,8 @@ lookdict(PyDictObject *mp, PyObject *key, } } else { - PyErr_SetString(PyExc_RuntimeError, - "dictionary changed size during lookup"); - return NULL; + /* The dict was mutated, restart */ + goto top; } } else if (ep->me_key == dummy && freeslot == NULL) |