[Python-checkins] r69436 - python/trunk/Objects/object.c
mark.dickinson
python-checkins at python.org
Sun Feb 8 15:42:28 CET 2009
Author: mark.dickinson
Date: Sun Feb 8 15:42:28 2009
New Revision: 69436
Log:
Issue #789290: make sure that hash(2**63) == hash(2.**63) on 64-bit
platforms. The previous code was fragile, depending on the twin
accidents that:
(1) in C, casting the double value 2.**63 to long returns the integer
value -2**63, and
(2) in Python, hash(-2**63) == hash(2**63).
There's already a test for this in test_hash.
Modified:
python/trunk/Objects/object.c
Modified: python/trunk/Objects/object.c
==============================================================================
--- python/trunk/Objects/object.c (original)
+++ python/trunk/Objects/object.c Sun Feb 8 15:42:28 2009
@@ -1028,7 +1028,7 @@
fractpart = modf(v, &intpart);
if (fractpart == 0.0) {
/* This must return the same hash as an equal int or long. */
- if (intpart > LONG_MAX || -intpart > LONG_MAX) {
+ if (intpart > LONG_MAX/2 || -intpart > LONG_MAX/2) {
/* Convert to long and use its hash. */
PyObject *plong; /* converted to Python long */
if (Py_IS_INFINITY(intpart))
More information about the Python-checkins
mailing list