[Python-checkins] python/dist/src/Objects typeobject.c,2.170,2.171
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Fri, 09 Aug 2002 22:41:32 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv19677
Modified Files:
typeobject.c
Log Message:
Disallow class assignment completely unless both old and new are heap
types. This prevents nonsense like 2.__class__ = bool or
True.__class__ = int.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.170
retrieving revision 2.171
diff -C2 -d -r2.170 -r2.171
*** typeobject.c 9 Aug 2002 02:14:34 -0000 2.170
--- typeobject.c 10 Aug 2002 05:41:29 -0000 2.171
***************
*** 1746,1749 ****
--- 1746,1756 ----
}
new = (PyTypeObject *)value;
+ if (!(new->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
+ !(old->tp_flags & Py_TPFLAGS_HEAPTYPE))
+ {
+ PyErr_Format(PyExc_TypeError,
+ "__class__ assignment: only for heap types");
+ return -1;
+ }
if (new->tp_dealloc != old->tp_dealloc ||
new->tp_free != old->tp_free)
***************
*** 1772,1782 ****
return -1;
}
! if (new->tp_flags & Py_TPFLAGS_HEAPTYPE) {
! Py_INCREF(new);
! }
self->ob_type = new;
! if (old->tp_flags & Py_TPFLAGS_HEAPTYPE) {
! Py_DECREF(old);
! }
return 0;
}
--- 1779,1785 ----
return -1;
}
! Py_INCREF(new);
self->ob_type = new;
! Py_DECREF(old);
return 0;
}