[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.113,2.114
Tim Peters
tim_one@users.sourceforge.net
Sat, 27 Oct 2001 12:37:50 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv12753/python/Objects
Modified Files:
typeobject.c
Log Message:
SF bug #475327: type() produces incorrect error msg
object.h: Added PyType_CheckExact macro.
typeobject.c, type_new():
+ Use the new macro.
+ Assert that the arguments have the right types rather than do incomplete
runtime checks "sometimes".
+ If this isn't the 1-argument flavor() of type, and there aren't 3 args
total, produce a "types() takes 1 or 3 args" msg before
PyArg_ParseTupleAndKeywords produces a "takes exactly 3" msg.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.113
retrieving revision 2.114
diff -C2 -d -r2.113 -r2.114
*** typeobject.c 2001/10/26 04:26:11 2.113
--- typeobject.c 2001/10/27 19:37:48 2.114
***************
*** 714,724 ****
int i, nbases, nslots, slotoffset, add_dict, add_weak;
/* Special case: type(x) should return x->ob_type */
! if (metatype == &PyType_Type &&
! PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
! (kwds == NULL || (PyDict_Check(kwds) && PyDict_Size(kwds) == 0))) {
! PyObject *x = PyTuple_GET_ITEM(args, 0);
! Py_INCREF(x->ob_type);
! return (PyObject *) x->ob_type;
}
--- 714,739 ----
int i, nbases, nslots, slotoffset, add_dict, add_weak;
+ assert(args != NULL && PyTuple_Check(args));
+ assert(kwds == NULL || PyDict_Check(kwds));
+
/* Special case: type(x) should return x->ob_type */
! {
! const int nargs = PyTuple_GET_SIZE(args);
! const int nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
!
! if (PyType_CheckExact(metatype) && nargs == 1 && nkwds == 0) {
! PyObject *x = PyTuple_GET_ITEM(args, 0);
! Py_INCREF(x->ob_type);
! return (PyObject *) x->ob_type;
! }
!
! /* SF bug 475327 -- if that didn't trigger, we need 3
! arguments. but PyArg_ParseTupleAndKeywords below may give
! a msg saying type() needs exactly 3. */
! if (nargs + nkwds != 3) {
! PyErr_SetString(PyExc_TypeError,
! "type() takes 1 or 3 arguments");
! return NULL;
! }
}