diff -r 8a3303a8a87c Objects/odictobject.c --- a/Objects/odictobject.c Thu Sep 03 09:46:24 2015 +0200 +++ b/Objects/odictobject.c Thu Sep 03 11:51:23 2015 +0200 @@ -98,7 +98,6 @@ For removing nodes: Others: -* _odict_initialize(od) * _odict_find_node(od, key) * _odict_keys_equal(od1, od2) @@ -602,15 +601,6 @@ static Py_ssize_t return _odict_get_index_hash(od, key, hash); } -static int -_odict_initialize(PyODictObject *od) -{ - od->od_state = 0; - _odict_FIRST(od) = NULL; - _odict_LAST(od) = NULL; - return _odict_resize((PyODictObject *)od); -} - /* Returns NULL if there was some error or the key was not found. */ static _ODictNode * _odict_find_node(PyODictObject *od, PyObject *key) @@ -1739,14 +1729,25 @@ odict_init(PyObject *self, PyObject *arg static PyObject * odict_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { - PyObject *od = PyDict_Type.tp_new(type, args, kwds); - if (od != NULL) { - if (_odict_initialize((PyODictObject *)od) < 0) + PyObject *op = PyDict_Type.tp_new(type, args, kwds); + PyODictObject *od; + if (op == NULL) return NULL; - ((PyODictObject *)od)->od_inst_dict = PyDict_New(); - ((PyODictObject *)od)->od_weakreflist = NULL; - } - return od; + + od = (PyODictObject *)op; + /* dict constructor fills the object with zeros, + see PyType_GenericAlloc(), no need to reset them again */ + od->od_inst_dict = PyDict_New(); + if (od->od_inst_dict == NULL) + goto error; + if (_odict_resize(od) < 0) + goto error; + + return op; + +error: + Py_DECREF(od); + return NULL; } /* PyODict_Type */