[Python-checkins] cpython: Issue #18408: dict_new() now fails on new_keys_object() error
victor.stinner
python-checkins at python.org
Tue Jul 16 23:09:21 CEST 2013
http://hg.python.org/cpython/rev/b7c6d203c9fb
changeset: 84674:b7c6d203c9fb
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jul 16 22:19:00 2013 +0200
summary:
Issue #18408: dict_new() now fails on new_keys_object() error
Pass the MemoryError exception to the caller, instead of using empty keys.
files:
Objects/dictobject.c | 19 +++++++++----------
1 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1395,7 +1395,7 @@
}
DK_DECREF(keys);
}
- else {
+ else if (keys != NULL) {
assert(keys->dk_refcnt == 1);
DK_DECREF(keys);
}
@@ -2595,19 +2595,18 @@
self = type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
-
d = (PyDictObject *)self;
- d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED);
- /* XXX - Should we raise a no-memory error? */
- if (d->ma_keys == NULL) {
- DK_INCREF(Py_EMPTY_KEYS);
- d->ma_keys = Py_EMPTY_KEYS;
- d->ma_values = empty_values;
- }
- d->ma_used = 0;
+
/* The object has been implicitly tracked by tp_alloc */
if (type == &PyDict_Type)
_PyObject_GC_UNTRACK(d);
+
+ d->ma_used = 0;
+ d->ma_keys = new_keys_object(PyDict_MINSIZE_COMBINED);
+ if (d->ma_keys == NULL) {
+ Py_DECREF(self);
+ return NULL;
+ }
return self;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list