diff options
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 677221a..362d0ad 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2232,14 +2232,45 @@ long_compare(PyLongObject *a, PyLongObject *b) return sign < 0 ? -1 : sign > 0 ? 1 : 0; } +#define TEST_COND(cond) \ + ((cond) ? Py_True : Py_False) + static PyObject * long_richcompare(PyObject *self, PyObject *other, int op) { - PyObject *result; + int result; + PyObject *v; CHECK_BINOP(self, other); - result = Py_CmpToRich(op, long_compare((PyLongObject*)self, - (PyLongObject*)other)); - return result; + if (self == other) + result = 0; + else + result = long_compare((PyLongObject*)self, (PyLongObject*)other); + /* Convert the return value to a Boolean */ + switch (op) { + case Py_EQ: + v = TEST_COND(result == 0); + break; + case Py_NE: + v = TEST_COND(result != 0); + break; + case Py_LE: + v = TEST_COND(result <= 0); + break; + case Py_GE: + v = TEST_COND(result >= 0); + break; + case Py_LT: + v = TEST_COND(result == -1); + break; + case Py_GT: + v = TEST_COND(result == 1); + break; + default: + PyErr_BadArgument(); + return NULL; + } + Py_INCREF(v); + return v; } static long |