summaryrefslogtreecommitdiffstats
path: root/Objects/dictobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-07-16 20:19:00 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-07-16 20:19:00 (GMT)
commitac2a4fe8a20961590cc20cde2afd7cf0fc9ce8b2 (patch)
tree4cc2c5be60d5e957768450832b007323a6756875 /Objects/dictobject.c
parenta9f61a5a2345b72802c8604fb4f45f06df75a719 (diff)
downloadcpython-ac2a4fe8a20961590cc20cde2afd7cf0fc9ce8b2.zip
cpython-ac2a4fe8a20961590cc20cde2afd7cf0fc9ce8b2.tar.gz
cpython-ac2a4fe8a20961590cc20cde2afd7cf0fc9ce8b2.tar.bz2
Issue #18408: dict_new() now fails on new_keys_object() error
Pass the MemoryError exception to the caller, instead of using empty keys.
Diffstat (limited to 'Objects/dictobject.c')
-rw-r--r--Objects/dictobject.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index d02ef02..3243061 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -1395,7 +1395,7 @@ dict_dealloc(PyDictObject *mp)
}
DK_DECREF(keys);
}
- else {
+ else if (keys != NULL) {
assert(keys->dk_refcnt == 1);
DK_DECREF(keys);
}
@@ -2595,19 +2595,18 @@ dict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
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;
}