diff options
author | Guido van Rossum <guido@python.org> | 2001-10-03 13:58:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-10-03 13:58:35 (GMT) |
commit | 1e1de1cf35ebd6b3cfcc20e40991fa437b8e9864 (patch) | |
tree | fa5a50c8634bd19a3c6e74f090208b501ad4af2c /Objects | |
parent | ae3b1258e48281fd44f48a0a93ff582ae57f6c70 (diff) | |
download | cpython-1e1de1cf35ebd6b3cfcc20e40991fa437b8e9864.zip cpython-1e1de1cf35ebd6b3cfcc20e40991fa437b8e9864.tar.gz cpython-1e1de1cf35ebd6b3cfcc20e40991fa437b8e9864.tar.bz2 |
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.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/typeobject.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index d976945..c50b446 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -3296,8 +3296,20 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name) } 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; return PyObject_GenericGetAttr(self, name); |