[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.63,2.64
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 18 Sep 2001 13:03:59 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv17589
Modified Files:
typeobject.c
Log Message:
wrap_cmpfunc(): added a safety check for the __cmp__ wrapper. We can
only safely call a type's tp_compare slot if the second argument is
also an instance of the same type. I hate to think what
e.g. int_compare() would do with a second argument that's a float!
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.63
retrieving revision 2.64
diff -C2 -d -r2.63 -r2.64
*** typeobject.c 2001/09/18 00:23:33 2.63
--- typeobject.c 2001/09/18 20:03:57 2.64
***************
*** 2034,2037 ****
--- 2034,2046 ----
if (!PyArg_ParseTuple(args, "O", &other))
return NULL;
+ if (!PyType_IsSubtype(other->ob_type, self->ob_type)) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "%s.__cmp__(x,y) requires y to be a '%s', not a '%s'",
+ self->ob_type->tp_name,
+ self->ob_type->tp_name,
+ other->ob_type->tp_name);
+ return NULL;
+ }
res = (*func)(self, other);
if (PyErr_Occurred())