summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index dfad1ec..b1bee90 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1038,38 +1038,35 @@ wrapper_dealloc(wrapperobject *wp)
static PyObject *
wrapper_richcompare(PyObject *a, PyObject *b, int op)
{
- PyWrapperDescrObject *a_descr, *b_descr;
+ wrapperobject *wa, *wb;
+ int eq;
assert(a != NULL && b != NULL);
/* both arguments should be wrapperobjects */
- if (!Wrapper_Check(a) || !Wrapper_Check(b)) {
+ if ((op != Py_EQ && op != Py_NE)
+ || !Wrapper_Check(a) || !Wrapper_Check(b))
+ {
Py_RETURN_NOTIMPLEMENTED;
}
- /* compare by descriptor address; if the descriptors are the same,
- compare by the objects they're bound to */
- a_descr = ((wrapperobject *)a)->descr;
- b_descr = ((wrapperobject *)b)->descr;
- if (a_descr == b_descr) {
- a = ((wrapperobject *)a)->self;
- b = ((wrapperobject *)b)->self;
- return PyObject_RichCompare(a, b, op);
+ wa = (wrapperobject *)a;
+ wb = (wrapperobject *)b;
+ eq = (wa->descr == wb->descr && wa->self == wb->self);
+ if (eq == (op == Py_EQ)) {
+ Py_RETURN_TRUE;
+ }
+ else {
+ Py_RETURN_FALSE;
}
-
- Py_RETURN_RICHCOMPARE(a_descr, b_descr, op);
}
static Py_hash_t
wrapper_hash(wrapperobject *wp)
{
Py_hash_t x, y;
- x = _Py_HashPointer(wp->descr);
- if (x == -1)
- return -1;
- y = PyObject_Hash(wp->self);
- if (y == -1)
- return -1;
+ x = _Py_HashPointer(wp->self);
+ y = _Py_HashPointer(wp->descr);
x = x ^ y;
if (x == -1)
x = -2;