[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.85,2.86

Guido van Rossum gvanrossum@users.sourceforge.net
2001年10月03日 06:58:37 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv20203
Modified Files:
	typeobject.c 
Log Message:
typeobject.c, slot_tp_gettattr_hook(): fix the speedup hack -- the
test for getattribute==NULL was bogus because it always found
object.__getattribute__. Pick it apart using the trick we learned
from slot_sq_item, and if it's just a wrapper around
PyObject_GenericGetAttr, zap it. Also added a long XXX comment
explaining the consequences.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.85
retrieving revision 2.86
diff -C2 -d -r2.85 -r2.86
*** typeobject.c	2001年10月03日 12:09:30	2.85
--- typeobject.c	2001年10月03日 13:58:35	2.86
***************
*** 3297,3302 ****
--- 3297,3314 ----
 	getattr = _PyType_Lookup(tp, getattr_str);
 	getattribute = _PyType_Lookup(tp, getattribute_str);
+ 	if (getattribute != NULL &&
+ 	 getattribute->ob_type == &PyWrapperDescr_Type &&
+ 	 ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
+ 	 PyObject_GenericGetAttr)
+ 		 getattribute = NULL;
 	if (getattr == NULL && getattribute == NULL) {
 		/* Avoid further slowdowns */
+ 		/* XXX This is questionable: it means that a class that
+ 		 isn't born with __getattr__ or __getattribute__ cannot
+ 		 acquire them in later life. But it's a relatively big
+ 		 speedup, so I'm keeping it in for now. If this is
+ 		 removed, you can also remove the "def __getattr__" from
+ 		 class C (marked with another XXX comment) in dynamics()
+ 		 in Lib/test/test_descr.py. */
 		if (tp->tp_getattro == slot_tp_getattr_hook)
 			tp->tp_getattro = PyObject_GenericGetAttr;

AltStyle によって変換されたページ (->オリジナル) /