[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.112,2.113
Guido van Rossum
gvanrossum@users.sourceforge.net
Thu, 25 Oct 2001 21:26:14 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv9797/Objects
Modified Files:
typeobject.c
Log Message:
Allow assignment to newinstance.__dict__.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.112
retrieving revision 2.113
diff -C2 -d -r2.112 -r2.113
*** typeobject.c 2001/10/22 00:43:43 2.112
--- typeobject.c 2001/10/26 04:26:11 2.113
***************
*** 675,680 ****
}
static PyGetSetDef subtype_getsets[] = {
! {"__dict__", subtype_dict, NULL, NULL},
{0},
};
--- 675,703 ----
}
+ static int
+ subtype_setdict(PyObject *obj, PyObject *value, void *context)
+ {
+ PyObject **dictptr = _PyObject_GetDictPtr(obj);
+ PyObject *dict;
+
+ if (dictptr == NULL) {
+ PyErr_SetString(PyExc_AttributeError,
+ "This object has no __dict__");
+ return -1;
+ }
+ if (value == NULL || !PyDict_Check(value)) {
+ PyErr_SetString(PyExc_TypeError,
+ "__dict__ must be set to a dictionary");
+ return -1;
+ }
+ dict = *dictptr;
+ Py_INCREF(value);
+ *dictptr = value;
+ Py_XDECREF(dict);
+ return 0;
+ }
+
static PyGetSetDef subtype_getsets[] = {
! {"__dict__", subtype_dict, subtype_setdict, NULL},
{0},
};