[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.107,2.108
Guido van Rossum
gvanrossum@users.sourceforge.net
2001年10月17日 06:59:11 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv25388
Modified Files:
typeobject.c
Log Message:
Remove a bunch of stuff that's no longer needed now that update_slot()
and fixup_slot_dispatchers() always select the proper slot dispatcher.
This affects slot_sq_item(), slot_tp_getattro(), and
slot_tp_getattr_hook().
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.107
retrieving revision 2.108
diff -C2 -d -r2.107 -r2.108
*** typeobject.c 2001年10月17日 07:15:43 2.107
--- typeobject.c 2001年10月17日 13:59:09 2.108
***************
*** 2906,2919 ****
func = _PyType_Lookup(self->ob_type, getitem_str);
if (func != NULL) {
- if (func->ob_type == &PyWrapperDescr_Type) {
- PyWrapperDescrObject *wrapper =
- (PyWrapperDescrObject *)func;
- if (wrapper->d_base->wrapper == wrap_sq_item &&
- PyType_IsSubtype(self->ob_type, wrapper->d_type)) {
- intargfunc f;
- f = (intargfunc)(wrapper->d_wrapped);
- return f(self, i);
- }
- }
if ((f = func->ob_type->tp_descr_get) == NULL)
Py_INCREF(func);
--- 2906,2909 ----
***************
*** 3314,3337 ****
}
static PyObject *
slot_tp_getattro(PyObject *self, PyObject *name)
{
! PyTypeObject *tp = self->ob_type;
! PyObject *getattr;
! static PyObject *getattr_str = NULL;
!
! if (getattr_str == NULL) {
! getattr_str = PyString_InternFromString("__getattribute__");
! if (getattr_str == NULL)
! return NULL;
! }
! getattr = _PyType_Lookup(tp, getattr_str);
! if (getattr == NULL) {
! /* Avoid further slowdowns */
! if (tp->tp_getattro == slot_tp_getattro)
! tp->tp_getattro = PyObject_GenericGetAttr;
! return PyObject_GenericGetAttr(self, name);
! }
! return PyObject_CallFunction(getattr, "OO", self, name);
}
--- 3304,3324 ----
}
+ /* There are two slot dispatch functions for tp_getattro.
+
+ - slot_tp_getattro() is used when __getattribute__ is overridden
+ but no __getattr__ hook is present;
+
+ - slot_tp_getattr_hook() is used when a __getattr__ hook is present.
+
+ The code in update_slot() and fixup_slot_dispatchers() always installs
+ slot_tp_getattr_hook(); this detects the absence of __getattr__ and then
+ installs the simpler slot if necessary. */
+
static PyObject *
slot_tp_getattro(PyObject *self, PyObject *name)
{
! static PyObject *getattribute_str = NULL;
! return call_method(self, "__getattribute__", &getattribute_str,
! "(O)", name);
}
***************
*** 3356,3360 ****
}
getattr = _PyType_Lookup(tp, getattr_str);
! if (getattr == NULL && tp->tp_getattro == slot_tp_getattr_hook) {
/* No __getattr__ hook: use a simpler dispatcher */
tp->tp_getattro = slot_tp_getattro;
--- 3343,3347 ----
}
getattr = _PyType_Lookup(tp, getattr_str);
! if (getattr == NULL) {
/* No __getattr__ hook: use a simpler dispatcher */
tp->tp_getattro = slot_tp_getattro;
***************
*** 3362,3382 ****
}
getattribute = _PyType_Lookup(tp, getattribute_str);
! if (getattribute != NULL &&
! getattribute->ob_type == &PyWrapperDescr_Type &&
! ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
! (void *)PyObject_GenericGetAttr)
! getattribute = NULL;
! if (getattr == NULL && getattribute == NULL) {
! /* Use the default dispatcher */
! if (tp->tp_getattro == slot_tp_getattr_hook)
! tp->tp_getattro = PyObject_GenericGetAttr;
! return PyObject_GenericGetAttr(self, name);
! }
! if (getattribute == NULL)
res = PyObject_GenericGetAttr(self, name);
else
res = PyObject_CallFunction(getattribute, "OO", self, name);
! if (getattr != NULL &&
! res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
res = PyObject_CallFunction(getattr, "OO", self, name);
--- 3349,3360 ----
}
getattribute = _PyType_Lookup(tp, getattribute_str);
! if (getattribute == NULL ||
! (getattribute->ob_type == &PyWrapperDescr_Type &&
! ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
! (void *)PyObject_GenericGetAttr))
res = PyObject_GenericGetAttr(self, name);
else
res = PyObject_CallFunction(getattribute, "OO", self, name);
! if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
res = PyObject_CallFunction(getattr, "OO", self, name);