[Python-bugs-list] [ python-Bugs-689659 ] 64-bit int and long hash keys incompatible
SourceForge.net
noreply@sourceforge.net
Wed, 19 Feb 2003 15:29:45 -0800
Bugs item #689659, was opened at 2003-02-19 18:17
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=689659&group_id=5470
Category: Python Interpreter Core
Group: Platform-specific
Status: Open
Resolution: None
>Priority: 6
Submitted By: Mark Dickinson (marketdickinson)
>Assigned to: Tim Peters (tim_one)
Summary: 64-bit int and long hash keys incompatible
Initial Comment:
For 64-bit platforms, it seems that ints and longs with the
same value don't necessarily give the same hash key.
An example is below; the phenomenon seems to occur
for a range of numbers between 2**32 and 2**64.
I assume this is unintentional? It looks suspiciously as
though the function long_hash in Objects/longobject.c
has 32-bitness hard-coded. Lines 1288-1289 of that file
in the Python 2.2.2 source read:
/* Force a 32-bit circular shift */
x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) &
MASK);
And here's the Python example:
Python 2.2.2 (#22, Dec 23 2002, 12:02:55)
[GCC 3.0.3] on sunos5
Type "help", "copyright", "credits" or "license" for more
information.
>>> x = 4503599627370496L
>>> y = 4503599627370496
>>> h = {x: 'anything', y: 'something else'}
>>> h[x]
'anything'
>>> h[y]
'something else'
>>> x == y
1
All the best,
Mark
----------------------------------------------------------------------
>Comment By: Tim Peters (tim_one)
Date: 2003-02-19 18:29
Message:
Logged In: YES
user_id=31435
Good catch! Agreed on all counts, and boosted priority
because Python is trying to blur the distinction between
ints and longs, so that this is likely to bite harder in the
future. Assigned to me, but a patch would be appreciated
(don't know when I can make time for this, and I don't have
a 64-bit box for testing).
It should be enough to replace "32" with "8*sizeof(long)".
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=689659&group_id=5470