diff options
author | stratakis <cstratak@redhat.com> | 2017-11-02 11:32:54 +0100 |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2017-11-02 20:32:54 +1000 |
commit | e8b19656396381407ad91473af5da8b0d4346e88 (patch) | |
tree | 16638970d5014728a49808d0c80c4af0fe6ccb91 /Objects/descrobject.c | |
parent | bpo-27666: Fixed stack corruption in curses.box() and curses.ungetmouse(). (#... (diff) | |
download | cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.gz cpython-e8b19656396381407ad91473af5da8b0d4346e88.tar.bz2 cpython-e8b19656396381407ad91473af5da8b0d4346e88.zip |
bpo-23699: Use a macro to reduce boilerplate code in rich comparison functions (GH-793)
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r-- | Objects/descrobject.c | 35 |
1 files changed, 2 insertions, 33 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c index 5dc27ef6727..71d522433a2 100644 --- a/Objects/descrobject.c +++ b/Objects/descrobject.c @@ -1035,22 +1035,16 @@ wrapper_dealloc(wrapperobject *wp) Py_TRASHCAN_SAFE_END(wp) } -#define TEST_COND(cond) ((cond) ? Py_True : Py_False) - static PyObject * wrapper_richcompare(PyObject *a, PyObject *b, int op) { - intptr_t result; - PyObject *v; PyWrapperDescrObject *a_descr, *b_descr; assert(a != NULL && b != NULL); /* both arguments should be wrapperobjects */ if (!Wrapper_Check(a) || !Wrapper_Check(b)) { - v = Py_NotImplemented; - Py_INCREF(v); - return v; + Py_RETURN_NOTIMPLEMENTED; } /* compare by descriptor address; if the descriptors are the same, @@ -1063,32 +1057,7 @@ wrapper_richcompare(PyObject *a, PyObject *b, int op) return PyObject_RichCompare(a, b, op); } - result = a_descr - b_descr; - 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(a_descr, b_descr, op); } static Py_hash_t |