[Python-checkins] CVS: python/dist/src/Objects floatobject.c,2.99,2.100 intobject.c,2.75,2.76 longobject.c,1.108,1.109
Guido van Rossum
gvanrossum@users.sourceforge.net
Tue, 18 Sep 2001 18:25:18 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv21068/Objects
Modified Files:
floatobject.c intobject.c longobject.c
Log Message:
Add additional coercion support for "self subtypes" to int, long,
float (compare the recent checkin to complex). Added tests for these.
Index: floatobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/floatobject.c,v
retrieving revision 2.99
retrieving revision 2.100
diff -C2 -d -r2.99 -r2.100
*** floatobject.c 2001/09/12 19:12:49 2.99
--- floatobject.c 2001/09/19 01:25:15 2.100
***************
*** 591,594 ****
--- 591,599 ----
return 0;
}
+ else if (PyFloat_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
return 1; /* Can't do it */
}
Index: intobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/intobject.c,v
retrieving revision 2.75
retrieving revision 2.76
diff -C2 -d -r2.75 -r2.76
*** intobject.c 2001/09/15 03:14:32 2.75
--- intobject.c 2001/09/19 01:25:15 2.76
***************
*** 783,786 ****
--- 783,797 ----
}
+ static int
+ int_coerce(PyObject **pv, PyObject **pw)
+ {
+ if (PyInt_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
+ return 1; /* Can't do it */
+ }
+
static PyObject *
int_int(PyIntObject *v)
***************
*** 905,909 ****
(binaryfunc)int_xor, /*nb_xor*/
(binaryfunc)int_or, /*nb_or*/
! 0, /*nb_coerce*/
(unaryfunc)int_int, /*nb_int*/
(unaryfunc)int_long, /*nb_long*/
--- 916,920 ----
(binaryfunc)int_xor, /*nb_xor*/
(binaryfunc)int_or, /*nb_or*/
! int_coerce, /*nb_coerce*/
(unaryfunc)int_int, /*nb_int*/
(unaryfunc)int_long, /*nb_long*/
Index: longobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/longobject.c,v
retrieving revision 1.108
retrieving revision 1.109
diff -C2 -d -r1.108 -r1.109
*** longobject.c 2001/09/15 03:14:32 1.108
--- longobject.c 2001/09/19 01:25:15 1.109
***************
*** 2135,2138 ****
--- 2135,2143 ----
return 0;
}
+ else if (PyLong_Check(*pw)) {
+ Py_INCREF(*pv);
+ Py_INCREF(*pw);
+ return 0;
+ }
return 1; /* Can't do it */
}