[Python-checkins] CVS: python/dist/src/Python ceval.c,2.232,2.233

Guido van Rossum gvanrossum@users.sourceforge.net
Wed, 21 Mar 2001 11:17:24 -0800


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

Modified Files:
	ceval.c 
Log Message:
Use PyObject_IsInstance() to check whether the first argument to an
unbound method is of the right type.  Hopefully this solves SF patch
#409355 (Meta-class inheritance problem); I have no easy way to test.


Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.232
retrieving revision 2.233
diff -C2 -r2.232 -r2.233
*** ceval.c	2001/03/21 16:43:46	2.232
--- ceval.c	2001/03/21 19:17:22	2.233
***************
*** 1403,1407 ****
  			why = WHY_BREAK;
  			break;
! 		
  		case CONTINUE_LOOP:
  			retval = PyInt_FromLong(oparg);
--- 1403,1407 ----
  			why = WHY_BREAK;
  			break;
! 
  		case CONTINUE_LOOP:
  			retval = PyInt_FromLong(oparg);
***************
*** 2182,2186 ****
  				/* For a continue inside a try block,
  				   don't pop the block for the loop. */
! 				PyFrame_BlockSetup(f, b->b_type, b->b_level, 
  						   b->b_handler);
  				why = WHY_NOT;
--- 2182,2186 ----
  				/* For a continue inside a try block,
  				   don't pop the block for the loop. */
! 				PyFrame_BlockSetup(f, b->b_type, b->b_level,
  						   b->b_handler);
  				why = WHY_NOT;
***************
*** 2826,2845 ****
  		/* Unbound methods must be called with an instance of
  		   the class (or a derived class) as first argument */
  		if (PyTuple_Size(arg) >= 1)
  			self = PyTuple_GET_ITEM(arg, 0);
! 		if (!(self != NULL && PyInstance_Check(self)
! 		    && PyClass_IsSubclass((PyObject *)
! 				  (((PyInstanceObject *)self)->in_class),
! 					  class))) {
!                 PyObject* fn = ((PyFunctionObject*) func)->func_name;
! 		PyErr_Format(PyExc_TypeError,
!                              "unbound method %s%smust be "
!                              "called with instance as first argument",
!                              fn ? PyString_AsString(fn) : "",
!                              fn ? "() " : "");
  			return NULL;
  		}
  		Py_INCREF(arg);
! 	} else {
  		int argcount = PyTuple_Size(arg);
  		PyObject *newarg = PyTuple_New(argcount + 1);
--- 2826,2851 ----
  		/* Unbound methods must be called with an instance of
  		   the class (or a derived class) as first argument */
+ 		int ok;
  		if (PyTuple_Size(arg) >= 1)
  			self = PyTuple_GET_ITEM(arg, 0);
! 		if (self == NULL)
! 			ok = 0;
! 		else {
! 			ok = PyObject_IsInstance(self, class);
! 			if (ok < 0)
! 				return NULL;
! 		}
! 		if (!ok) {
! 			PyObject* fn = ((PyFunctionObject*) func)->func_name;
! 			PyErr_Format(PyExc_TypeError,
! 				     "unbound method %s%smust be "
! 				     "called with instance as first argument",
! 				     fn ? PyString_AsString(fn) : "",
! 				     fn ? "() " : "");
  			return NULL;
  		}
  		Py_INCREF(arg);
! 	}
! 	else {
  		int argcount = PyTuple_Size(arg);
  		PyObject *newarg = PyTuple_New(argcount + 1);