[Python-checkins] CVS: python/dist/src/Modules operator.c,2.17,2.18
Fred L. Drake
fdrake@users.sourceforge.net
Thu, 09 Aug 2001 13:14:37 -0700
Update of /cvsroot/python/python/dist/src/Modules
In directory usw-pr-cvs1:/tmp/cvs-serv25902/Modules
Modified Files:
operator.c
Log Message:
Add wrappers around the rich-comparison operations.
This closes SF patch #428320.
Add wrappers to expose "floor" and "true" division.
This closes SF feature request #449093.
Index: operator.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/operator.c,v
retrieving revision 2.17
retrieving revision 2.18
diff -C2 -d -r2.17 -r2.18
*** operator.c 2000/09/17 16:09:27 2.17
--- operator.c 2001/08/09 20:14:34 2.18
***************
*** 111,114 ****
--- 111,119 ----
return PyInt_FromLong(r); }
+ #define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \
+ PyObject *a1, *a2; \
+ if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
+ return PyObject_RichCompare(a1,a2,A); }
+
spami(isCallable , PyCallable_Check)
spami(isNumberType , PyNumber_Check)
***************
*** 118,121 ****
--- 123,128 ----
spam2(op_mul , PyNumber_Multiply)
spam2(op_div , PyNumber_Divide)
+ spam2(op_floordiv , PyNumber_FloorDivide)
+ spam2(op_truediv , PyNumber_TrueDivide)
spam2(op_mod , PyNumber_Remainder)
spam1(op_neg , PyNumber_Negative)
***************
*** 141,144 ****
--- 148,157 ----
spam2n(op_delitem , PyObject_DelItem)
spam3n(op_setitem , PyObject_SetItem)
+ spamrc(op_lt , Py_LT)
+ spamrc(op_le , Py_LE)
+ spamrc(op_eq , Py_EQ)
+ spamrc(op_ne , Py_NE)
+ spamrc(op_gt , Py_GT)
+ spamrc(op_ge , Py_GE)
static PyObject*
***************
*** 215,219 ****
spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")
! spam2(div,__div__, "div(a, b) -- Same as a / b.")
spam2(mod,__mod__, "mod(a, b) -- Same as a % b.")
spam2(neg,__neg__, "neg(a) -- Same as -a.")
--- 228,234 ----
spam2(sub,__sub__, "sub(a, b) -- Same as a - b.")
spam2(mul,__mul__, "mul(a, b) -- Same as a * b.")
! spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.")
! spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.")
! spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b when __future__.division is in effect.")
spam2(mod,__mod__, "mod(a, b) -- Same as a % b.")
spam2(neg,__neg__, "neg(a) -- Same as -a.")
***************
*** 244,247 ****
--- 259,268 ----
spam2(delslice,__delslice__,
"delslice(a, b, c) -- Same as del a[b:c].")
+ spam2(lt,__lt__, "lt(a, b) -- Same as a<b.")
+ spam2(le,__le__, "le(a, b) -- Same as a<=b.")
+ spam2(eq,__eq__, "eq(a, b) -- Same as a==b.")
+ spam2(ne,__ne__, "ne(a, b) -- Same as a!=b.")
+ spam2(gt,__gt__, "gt(a, b) -- Same as a>b.")
+ spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.")
{NULL, NULL} /* sentinel */