Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e1de1c

Browse files
committed
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.
1 parent ae3b125 commit 1e1de1c

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

Objects/typeobject.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,8 +3296,20 @@ slot_tp_getattr_hook(PyObject *self, PyObject *name)
32963296
}
32973297
getattr = _PyType_Lookup(tp, getattr_str);
32983298
getattribute = _PyType_Lookup(tp, getattribute_str);
3299+
if (getattribute != NULL &&
3300+
getattribute->ob_type == &PyWrapperDescr_Type &&
3301+
((PyWrapperDescrObject *)getattribute)->d_wrapped ==
3302+
PyObject_GenericGetAttr)
3303+
getattribute = NULL;
32993304
if (getattr == NULL && getattribute == NULL) {
33003305
/* Avoid further slowdowns */
3306+
/* XXX This is questionable: it means that a class that
3307+
isn't born with __getattr__ or __getattribute__ cannot
3308+
acquire them in later life. But it's a relatively big
3309+
speedup, so I'm keeping it in for now. If this is
3310+
removed, you can also remove the "def __getattr__" from
3311+
class C (marked with another XXX comment) in dynamics()
3312+
in Lib/test/test_descr.py. */
33013313
if (tp->tp_getattro == slot_tp_getattr_hook)
33023314
tp->tp_getattro = PyObject_GenericGetAttr;
33033315
return PyObject_GenericGetAttr(self, name);

0 commit comments

Comments
 (0)