[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.108,2.109
Guido van Rossum
gvanrossum@users.sourceforge.net
Thu, 18 Oct 2001 08:49:23 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv23792/Objects
Modified Files:
typeobject.c
Log Message:
Fix SF bug #472234: type(obj) calls type->tp_init (Roeland Rengelink)
The fix is a band-aid: type_call() now makes the same exception for a
single-argument call to type() as type_new() was already making.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.108
retrieving revision 2.109
diff -C2 -d -r2.108 -r2.109
*** typeobject.c 2001/10/17 13:59:09 2.108
--- typeobject.c 2001/10/18 15:49:21 2.109
***************
*** 148,151 ****
--- 148,158 ----
obj = type->tp_new(type, args, kwds);
if (obj != NULL) {
+ /* Ugly exception: when the call was type(something),
+ don't call tp_init on the result. */
+ if (type == &PyType_Type &&
+ PyTuple_Check(args) && PyTuple_GET_SIZE(args) == 1 &&
+ (kwds == NULL ||
+ (PyDict_Check(kwds) && PyDict_Size(kwds) == 0)))
+ return obj;
type = obj->ob_type;
if (type->tp_init != NULL &&