[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.138,2.139

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 17 Aug 2001 06:43:29 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv27250

Modified Files:
	classobject.c 
Log Message:
instance_getattr2(): rewritten to remove unnecessary stuff and
streamlined a bit.

instancemethod_descr_get(): don't bind an unbound method of a class
that's not a base class of the argument class.


Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.138
retrieving revision 2.139
diff -C2 -d -r2.138 -r2.139
*** classobject.c	2001/08/17 12:07:34	2.138
--- classobject.c	2001/08/17 13:43:27	2.139
***************
*** 650,662 ****
  	descrgetfunc f;
  
- 	class = NULL;
  	v = PyDict_GetItem(inst->in_dict, name);
! 	if (v == NULL) {
! 		v = class_lookup(inst->in_class, name, &class);
! 		if (v == NULL)
! 			return v;
  	}
! 	Py_INCREF(v);
! 	if (class != NULL) {
  		f = v->ob_type->tp_descr_get;
  		if (f != NULL) {
--- 650,661 ----
  	descrgetfunc f;
  
  	v = PyDict_GetItem(inst->in_dict, name);
! 	if (v != NULL) {
! 		Py_INCREF(v);
! 		return v;
  	}
! 	v = class_lookup(inst->in_class, name, &class);
! 	if (v != NULL) {
! 		Py_INCREF(v);
  		f = v->ob_type->tp_descr_get;
  		if (f != NULL) {
***************
*** 666,682 ****
  			v = w;
  		}
- 		else if (PyMethod_Check(v)) {
- 			/* XXX This should be a tp_descr_get slot of
- 			   PyMethodObjects */
- 			PyObject *im_class = PyMethod_GET_CLASS(v);
- 			/* Only if classes are compatible */
- 			if (PyClass_IsSubclass((PyObject *)class, im_class)) {
- 				PyObject *im_func = PyMethod_GET_FUNCTION(v);
- 				PyObject *w = PyMethod_New(im_func,
- 						(PyObject *)inst, im_class);
- 				Py_DECREF(v);
- 				v = w;
- 			}
- 		}
  	}
  	return v;
--- 665,668 ----
***************
*** 2195,2202 ****
  
  static PyObject *
! instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *type)
  {
! 	if (PyMethod_GET_SELF(meth) != NULL) {
! 		/* Don't rebind an already bound method */
  		Py_INCREF(meth);
  		return meth;
--- 2181,2191 ----
  
  static PyObject *
! instancemethod_descr_get(PyObject *meth, PyObject *obj, PyObject *class)
  {
! 	/* Don't rebind an already bound method, or an unbound method
! 	   of a class that's not a base class of class */
! 	if (PyMethod_GET_SELF(meth) != NULL ||
! 	    (PyMethod_GET_CLASS(meth) != NULL &&
! 	     !PyObject_IsSubclass(class,  PyMethod_GET_CLASS(meth)))) {
  		Py_INCREF(meth);
  		return meth;
***************
*** 2204,2208 ****
  	if (obj == Py_None)
  		obj = NULL;
! 	return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj, type);
  }
  
--- 2193,2197 ----
  	if (obj == Py_None)
  		obj = NULL;
! 	return PyMethod_New(PyMethod_GET_FUNCTION(meth), obj, class);
  }