summaryrefslogtreecommitdiffstats
path: root/Objects/classobject.c
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2006-06-08 10:56:24 (GMT)
committerArmin Rigo <arigo@tunes.org>2006-06-08 10:56:24 (GMT)
commitfd01d7933bc3e9fd64d81961fbb7eabddcc82bc3 (patch)
tree04841c9342f5a07bd7436f8520aa2d54f0e54580 /Objects/classobject.c
parent996710fd44426f43d54034ebf3ee2355fca18f6a (diff)
downloadcpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.zip
cpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.tar.gz
cpython-fd01d7933bc3e9fd64d81961fbb7eabddcc82bc3.tar.bz2
(arre, arigo) SF bug #1350060
Give a consistent behavior for comparison and hashing of method objects (both user- and built-in methods). Now compares the 'self' recursively. The hash was already asking for the hash of 'self'.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r--Objects/classobject.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 6d2c648d..9e57269 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -2221,9 +2221,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 *
@@ -2299,7 +2307,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