diff options
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 79656f56dfd..aab35c75dea 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -2217,9 +2217,17 @@ instancemethod_dealloc(register PyMethodObject *im) static int instancemethod_compare(PyMethodObject *a, PyMethodObject *b) { - if (a->im_self != b->im_self) + int cmp; + cmp = PyObject_Compare(a->im_func, b->im_func); + if (cmp) + return cmp; + + if (a->im_self == b->im_self) + return 0; + if (a->im_self == NULL || b->im_self == NULL) return (a->im_self < b->im_self) ? -1 : 1; - return PyObject_Compare(a->im_func, b->im_func); + else + return PyObject_Compare(a->im_self, b->im_self); } static PyObject * @@ -2295,7 +2303,10 @@ instancemethod_hash(PyMethodObject *a) y = PyObject_Hash(a->im_func); if (y == -1) return -1; - return x ^ y; + x = x ^ y; + if (x == -1) + x = -2; + return x; } static int |