summaryrefslogtreecommitdiffstats
path: root/Objects/odictobject.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-02-08 14:39:05 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2016-02-08 14:39:05 (GMT)
commitd2962f145a4ad73ac5dad8ff9b3b26905d44d682 (patch)
treec567c994ef606269fc74192e9b5ce4d6c40193ef /Objects/odictobject.c
parent79ad8970523da6cad6b7485a98322197ab0f686b (diff)
downloadcpython-d2962f145a4ad73ac5dad8ff9b3b26905d44d682.zip
cpython-d2962f145a4ad73ac5dad8ff9b3b26905d44d682.tar.gz
cpython-d2962f145a4ad73ac5dad8ff9b3b26905d44d682.tar.bz2
Issue #25949: __dict__ for an OrderedDict instance is now created only when
needed.
Diffstat (limited to 'Objects/odictobject.c')
-rw-r--r--Objects/odictobject.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 1abdd02..dccbb3e 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1424,14 +1424,13 @@ static PyMethodDef odict_methods[] = {
* OrderedDict members
*/
-/* tp_members */
+/* tp_getset */
-static PyMemberDef odict_members[] = {
- {"__dict__", T_OBJECT, offsetof(PyODictObject, od_inst_dict), READONLY},
- {0}
+static PyGetSetDef odict_getset[] = {
+ {"__dict__", PyObject_GenericGetDict, PyObject_GenericSetDict},
+ {NULL}
};
-
/* ----------------------------------------------
* OrderedDict type slot methods
*/
@@ -1653,20 +1652,12 @@ odict_init(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject *
odict_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyObject *dict;
PyODictObject *od;
- dict = PyDict_New();
- if (dict == NULL)
- return NULL;
-
od = (PyODictObject *)PyDict_Type.tp_new(type, args, kwds);
- if (od == NULL) {
- Py_DECREF(dict);
+ if (od == NULL)
return NULL;
- }
- od->od_inst_dict = dict;
/* type constructor fills the memory with zeros (see
PyType_GenericAlloc()), there is no need to set them to zero again */
if (_odict_resize(od) < 0) {
@@ -1708,8 +1699,8 @@ PyTypeObject PyODict_Type = {
(getiterfunc)odict_iter, /* tp_iter */
0, /* tp_iternext */
odict_methods, /* tp_methods */
- odict_members, /* tp_members */
- 0, /* tp_getset */
+ 0, /* tp_members */
+ odict_getset, /* tp_getset */
&PyDict_Type, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */