diff options
author | stratakis <cstratak@redhat.com> | 2017-11-02 10:32:54 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-11-02 10:32:54 (GMT) |
commit | e8b19656396381407ad91473af5da8b0d4346e88 (patch) | |
tree | 16638970d5014728a49808d0c80c4af0fe6ccb91 /Objects/cellobject.c | |
parent | 4f469c096628af730b17798d0ebfd8925bfde836 (diff) | |
download | cpython-e8b19656396381407ad91473af5da8b0d4346e88.zip cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.bz2 |
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Objects/cellobject.c')
-rw-r--r-- | Objects/cellobject.c | 36 |
1 files changed, 2 insertions, 34 deletions
diff --git a/Objects/cellobject.c b/Objects/cellobject.c index af19229..7b05e61 100644 --- a/Objects/cellobject.c +++ b/Objects/cellobject.c @@ -53,22 +53,15 @@ cell_dealloc(PyCellObject *op) PyObject_GC_Del(op); } -#define TEST_COND(cond) ((cond) ? Py_True : Py_False) - static PyObject * cell_richcompare(PyObject *a, PyObject *b, int op) { - int result; - PyObject *v; - /* neither argument should be NULL, unless something's gone wrong */ assert(a != NULL && b != NULL); /* both arguments should be instances of PyCellObject */ if (!PyCell_Check(a) || !PyCell_Check(b)) { - v = Py_NotImplemented; - Py_INCREF(v); - return v; + Py_RETURN_NOTIMPLEMENTED; } /* compare cells by contents; empty cells come before anything else */ @@ -77,32 +70,7 @@ cell_richcompare(PyObject *a, PyObject *b, int op) if (a != NULL && b != NULL) return PyObject_RichCompare(a, b, op); - result = (b == NULL) - (a == NULL); - 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 < 0); - break; - case Py_GT: - v = TEST_COND(result > 0); - break; - default: - PyErr_BadArgument(); - return NULL; - } - Py_INCREF(v); - return v; + Py_RETURN_RICHCOMPARE(b == NULL, a == NULL, op); } static PyObject * |