[Python-checkins] python/dist/src/Objects typeobject.c,2.126.4.30,2.126.4.31

gvanrossum@users.sourceforge.net gvanrossum@users.sourceforge.net
Tue, 07 Jan 2003 13:47:57 -0800


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

Modified Files:
      Tag: release22-maint
	typeobject.c 
Log Message:
Backport typeobject.c revision 2.201 plus associated tests from 2.3:

Add a refinement to SLOT1BINFULL() that fixes the problem reported in
SF bug #623669: only try (e.g.) __rdiv__ before __div__ if the right
class actually overrides it.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.126.4.30
retrieving revision 2.126.4.31
diff -C2 -d -r2.126.4.30 -r2.126.4.31
*** typeobject.c	24 Dec 2002 14:48:41 -0000	2.126.4.30
--- typeobject.c	7 Jan 2003 21:47:44 -0000	2.126.4.31
***************
*** 2839,2842 ****
--- 2839,2876 ----
  }
  
+ /* Boolean helper for SLOT1BINFULL().
+    right.__class__ is a nontrivial subclass of left.__class__. */
+ static int
+ method_is_overloaded(PyObject *left, PyObject *right, char *name)
+ {
+ 	PyObject *a, *b;
+ 	int ok;
+ 
+ 	b = PyObject_GetAttrString((PyObject *)(right->ob_type), name);
+ 	if (b == NULL) {
+ 		PyErr_Clear();
+ 		/* If right doesn't have it, it's not overloaded */
+ 		return 0;
+ 	}
+ 
+ 	a = PyObject_GetAttrString((PyObject *)(left->ob_type), name);
+ 	if (a == NULL) {
+ 		PyErr_Clear();
+ 		Py_DECREF(b);
+ 		/* If right has it but left doesn't, it's overloaded */
+ 		return 1;
+ 	}
+ 
+ 	ok = PyObject_RichCompareBool(a, b, Py_NE);
+ 	Py_DECREF(a);
+ 	Py_DECREF(b);
+ 	if (ok < 0) {
+ 		PyErr_Clear();
+ 		return 0;
+ 	}
+ 
+ 	return ok;
+ }
+ 
  
  #define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR, ROPSTR) \
***************
*** 2852,2856 ****
  		PyObject *r; \
  		if (do_other && \
! 		    PyType_IsSubtype(other->ob_type, self->ob_type)) { \
  			r = call_maybe( \
  				other, ROPSTR, &rcache_str, "(O)", self); \
--- 2886,2891 ----
  		PyObject *r; \
  		if (do_other && \
! 		    PyType_IsSubtype(other->ob_type, self->ob_type) && \
! 		    method_is_overloaded(self, other, ROPSTR)) { \
  			r = call_maybe( \
  				other, ROPSTR, &rcache_str, "(O)", self); \