summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2007-09-19 21:19:28 (GMT)
committerThomas Wouters <thomas@python.org>2007-09-19 21:19:28 (GMT)
commitce272b6f8ac8997a4ff381e8804cddae8a6125c0 (patch)
tree20a2bc4b96b031bf2ff65a66dbcea67b8c3cbc4f /Objects
parent796d0b29e6fd09bf560d9e7e2a4f46cdc1cbf22a (diff)
downloadcpython-ce272b6f8ac8997a4ff381e8804cddae8a6125c0.zip
cpython-ce272b6f8ac8997a4ff381e8804cddae8a6125c0.tar.gz
cpython-ce272b6f8ac8997a4ff381e8804cddae8a6125c0.tar.bz2
Merged revisions 58203-58210 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r58204 | georg.brandl | 2007-09-19 08:37:19 +0200 (Wed, 19 Sep 2007) | 2 lines Fix #1169: remove docstrings in functions for -OO. ........ r58206 | sean.reifschneider | 2007-09-19 09:52:56 +0200 (Wed, 19 Sep 2007) | 2 lines issue1177: Ported Facundo's from urllib2 to urllib, accepting 2xx responses. ........ r58207 | facundo.batista | 2007-09-19 16:02:03 +0200 (Wed, 19 Sep 2007) | 3 lines Annotated the correction to urllib.py, issue #1177 ........ r58208 | facundo.batista | 2007-09-19 17:10:06 +0200 (Wed, 19 Sep 2007) | 7 lines Issue #1772851. Alters long.__hash__ from being *almost* completely predictable to being completely predictable. The value of hash(n) is unchanged for any n that's small enough to be representable as an int, and also unchanged for the vast majority of long integers n of reasonable size. ........ r58209 | thomas.wouters | 2007-09-19 19:27:29 +0200 (Wed, 19 Sep 2007) | 4 lines Fix obvious typo in threaded test. ........ r58210 | thomas.wouters | 2007-09-19 19:27:43 +0200 (Wed, 19 Sep 2007) | 4 lines Whitespace cleanup. ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/longobject.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 1c127ba..7f09bb6 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2197,10 +2197,18 @@ long_hash(PyLongObject *v)
i = -(i);
}
#define LONG_BIT_PyLong_SHIFT (8*sizeof(long) - PyLong_SHIFT)
+ /* The following loop produces a C long x such that (unsigned long)x
+ is congruent to the absolute value of v modulo ULONG_MAX. The
+ resulting x is nonzero if and only if v is. */
while (--i >= 0) {
/* Force a native long #-bits (32 or 64) circular shift */
x = ((x << PyLong_SHIFT) & ~PyLong_MASK) | ((x >> LONG_BIT_PyLong_SHIFT) & PyLong_MASK);
x += v->ob_digit[i];
+ /* If the addition above overflowed (thinking of x as
+ unsigned), we compensate by incrementing. This preserves
+ the value modulo ULONG_MAX. */
+ if ((unsigned long)x < v->ob_digit[i])
+ x++;
}
#undef LONG_BIT_PyLong_SHIFT
x = x * sign;