[Python-checkins] python/dist/src/Objects typeobject.c,2.201,2.202
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Tue, 07 Jan 2003 05:41:39 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv4861/Objects
Modified Files:
typeobject.c
Log Message:
Fix for SF bug #642358: only provide a new with a __dict__ or
__weaklist__ descriptor if we added __dict__ or __weaklist__,
respectively. With unit test.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.201
retrieving revision 2.202
diff -C2 -d -r2.201 -r2.202
*** typeobject.c 6 Jan 2003 22:57:47 -0000 2.201
--- typeobject.c 7 Jan 2003 13:41:36 -0000 2.202
***************
*** 1354,1362 ****
}
! static PyGetSetDef subtype_getsets[] = {
! /* Not all objects have these attributes!
! The descriptor's __get__ method may raise AttributeError. */
{"__dict__", subtype_dict, subtype_setdict,
PyDoc_STR("dictionary for instance variables (if defined)")},
{"__weakref__", subtype_getweakref, NULL,
PyDoc_STR("list of weak references to the object (if defined)")},
--- 1354,1374 ----
}
! /* Three variants on the subtype_getsets list. */
!
! static PyGetSetDef subtype_getsets_full[] = {
! {"__dict__", subtype_dict, subtype_setdict,
! PyDoc_STR("dictionary for instance variables (if defined)")},
! {"__weakref__", subtype_getweakref, NULL,
! PyDoc_STR("list of weak references to the object (if defined)")},
! {0}
! };
!
! static PyGetSetDef subtype_getsets_dict_only[] = {
{"__dict__", subtype_dict, subtype_setdict,
PyDoc_STR("dictionary for instance variables (if defined)")},
+ {0}
+ };
+
+ static PyGetSetDef subtype_getsets_weakref_only[] = {
{"__weakref__", subtype_getweakref, NULL,
PyDoc_STR("list of weak references to the object (if defined)")},
***************
*** 1811,1815 ****
type->tp_itemsize = base->tp_itemsize;
type->tp_members = et->members;
! type->tp_getset = subtype_getsets;
/* Special case some slots */
--- 1823,1835 ----
type->tp_itemsize = base->tp_itemsize;
type->tp_members = et->members;
!
! if (type->tp_weaklistoffset && type->tp_dictoffset)
! type->tp_getset = subtype_getsets_full;
! else if (type->tp_weaklistoffset && !type->tp_dictoffset)
! type->tp_getset = subtype_getsets_weakref_only;
! else if (!type->tp_weaklistoffset && type->tp_dictoffset)
! type->tp_getset = subtype_getsets_dict_only;
! else
! type->tp_getset = NULL;
/* Special case some slots */