summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2003-02-23 23:11:41 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2003-02-23 23:11:41 (GMT)
commitd5a65a77cfdd81ad6945195c88e367fcd9f709c2 (patch)
treeada89cc09c6e26fe8cc9f402840c738cc185bcd7 /Objects
parent97e3f0060c2607ca784a1895e7eb01cda5751eb6 (diff)
downloadcpython-d5a65a77cfdd81ad6945195c88e367fcd9f709c2.zip
cpython-d5a65a77cfdd81ad6945195c88e367fcd9f709c2.tar.gz
cpython-d5a65a77cfdd81ad6945195c88e367fcd9f709c2.tar.bz2
Fix SF bug #689659, 64-bit int and long hash keys incompatible
On a 64-bit machine, a dictionary could contain duplicate int/long keys if the value was > 2**32.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index c2d6ea7..446affb 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -1490,11 +1490,13 @@ long_hash(PyLongObject *v)
sign = -1;
i = -(i);
}
+#define LONG_BIT_SHIFT (8*sizeof(long) - SHIFT)
while (--i >= 0) {
- /* Force a 32-bit circular shift */
- x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) & MASK);
+ /* Force a native long #-bits (32 or 64) circular shift */
+ x = ((x << SHIFT) & ~MASK) | ((x >> LONG_BIT_SHIFT) & MASK);
x += v->ob_digit[i];
}
+#undef LONG_BIT_SHIFT
x = x * sign;
if (x == -1)
x = -2;