[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.95,2.96
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 09 Oct 2001 04:07:26 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv19027/Objects
Modified Files:
typeobject.c
Log Message:
It turned out not so difficult to support old-style numbers (those
without the Py_TPFLAGS_CHECKTYPES flag) in the wrappers. This
required a few changes in test_descr.py to cope with the fact that the
complex type has __int__, __long__ and __float__ methods that always
raise an exception.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.95
retrieving revision 2.96
diff -C2 -d -r2.95 -r2.96
*** typeobject.c 2001/10/08 16:49:26 2.95
--- typeobject.c 2001/10/09 11:07:24 2.96
***************
*** 1980,1983 ****
--- 1980,1999 ----
static PyObject *
+ wrap_binaryfunc_l(PyObject *self, PyObject *args, void *wrapped)
+ {
+ binaryfunc func = (binaryfunc)wrapped;
+ PyObject *other;
+
+ if (!PyArg_ParseTuple(args, "O", &other))
+ return NULL;
+ if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
+ self->ob_type != other->ob_type) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
+ return (*func)(self, other);
+ }
+
+ static PyObject *
wrap_binaryfunc_r(PyObject *self, PyObject *args, void *wrapped)
{
***************
*** 1987,1990 ****
--- 2003,2011 ----
if (!PyArg_ParseTuple(args, "O", &other))
return NULL;
+ if (!(self->ob_type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
+ self->ob_type != other->ob_type) {
+ Py_INCREF(Py_NotImplemented);
+ return Py_NotImplemented;
+ }
return (*func)(other, self);
}
***************
*** 1994,1998 ****
static struct wrapperbase tab_##NAME[] = { \
{"__" #NAME "__", \
! (wrapperfunc)wrap_binaryfunc, \
"x.__" #NAME "__(y) <==> " #OP}, \
{"__r" #NAME "__", \
--- 2015,2019 ----
static struct wrapperbase tab_##NAME[] = { \
{"__" #NAME "__", \
! (wrapperfunc)wrap_binaryfunc_l, \
"x.__" #NAME "__(y) <==> " #OP}, \
{"__r" #NAME "__", \
***************
*** 2779,2787 ****
}
! /* We don't support "old-style numbers" because their binary
! operators require that both arguments have the same type;
! the wrappers here only work for new-style numbers. */
! if ((type->tp_flags & Py_TPFLAGS_CHECKTYPES) &&
! (nb = type->tp_as_number) != NULL) {
ADD(nb->nb_add, tab_add);
ADD(nb->nb_subtract, tab_sub);
--- 2800,2804 ----
}
! if ((nb = type->tp_as_number) != NULL) {
ADD(nb->nb_add, tab_add);
ADD(nb->nb_subtract, tab_sub);
***************
*** 2818,2822 ****
ADD(nb->nb_inplace_xor, tab_ixor);
ADD(nb->nb_inplace_or, tab_ior);
! if (type->tp_flags & Py_TPFLAGS_CHECKTYPES) {
ADD(nb->nb_floor_divide, tab_floordiv);
ADD(nb->nb_true_divide, tab_truediv);
--- 2835,2839 ----
ADD(nb->nb_inplace_xor, tab_ixor);
ADD(nb->nb_inplace_or, tab_ior);
! if (type->tp_flags & Py_TPFLAGS_HAVE_CLASS) {
ADD(nb->nb_floor_divide, tab_floordiv);
ADD(nb->nb_true_divide, tab_truediv);