[Python-checkins] python/dist/src/Objects typeobject.c,2.126.4.29,2.126.4.30
nnorwitz@users.sourceforge.net
nnorwitz@users.sourceforge.net
Tue, 24 Dec 2002 06:48:43 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv29170/Objects
Modified Files:
Tag: release22-maint
typeobject.c
Log Message:
Fix SF #658106, Setting __class__ to NoneType
Backport Guido's checkin 2.171:
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.126.4.29
retrieving revision 2.126.4.30
diff -C2 -d -r2.126.4.29 -r2.126.4.30
*** typeobject.c 7 Dec 2002 02:28:17 -0000 2.126.4.29
--- typeobject.c 24 Dec 2002 14:48:41 -0000 2.126.4.30
***************
*** 1703,1706 ****
--- 1703,1713 ----
}
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;
+ }
newbase = new;
oldbase = old;
***************
*** 1719,1729 ****
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;
}
--- 1726,1732 ----
return -1;
}
! Py_INCREF(new);
self->ob_type = new;
! Py_DECREF(old);
return 0;
}