[Python-checkins] cpython (3.5): Issue #24726: Revert setting the value on the dict if

serhiy.storchaka python-checkins at python.org
Fri Nov 6 04:21:59 EST 2015


https://hg.python.org/cpython/rev/1594c23d8c2f
changeset: 98983:1594c23d8c2f
branch: 3.5
parent: 98981:ad44d551c13c
user: Serhiy Storchaka <storchaka at gmail.com>
date: Fri Nov 06 11:07:11 2015 +0200
summary:
 Issue #24726: Revert setting the value on the dict if
_odict_add_new_node() fails.
files:
 Objects/odictobject.c | 8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1721,7 +1721,13 @@
 int res = PyDict_SetItem(od, key, value);
 if (res == 0) {
 res = _odict_add_new_node((PyODictObject *)od, key);
- /* XXX Revert setting the value on the dict? */
+ if (res < 0) {
+ /* Revert setting the value on the dict */
+ PyObject *exc, *val, *tb;
+ PyErr_Fetch(&exc, &val, &tb);
+ (void) PyDict_DelItem(od, key);
+ _PyErr_ChainExceptions(exc, val, tb);
+ }
 }
 return res;
 };
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /