summaryrefslogtreecommitdiff
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorstratakis <cstratak@redhat.com>2017-11-02 11:32:54 +0100
committerNick Coghlan <ncoghlan@gmail.com>2017-11-02 20:32:54 +1000
commite8b19656396381407ad91473af5da8b0d4346e88 (patch)
tree16638970d5014728a49808d0c80c4af0fe6ccb91 /Objects/longobject.c
parent4f469c096628af730b17798d0ebfd8925bfde836 (diff)
downloadcpython-git-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c31
1 files changed, 1 insertions, 30 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index c71b783cc0..6fd4feba12 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2915,45 +2915,16 @@ 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)
{
int result;
- PyObject *v;
CHECK_BINOP(self, other);
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;
+ Py_RETURN_RICHCOMPARE(result, 0, op);
}
static Py_hash_t