This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 64-bit int and long hash keys incompatible
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: nnorwitz Nosy List: mark.dickinson, nnorwitz, tim.peters
Priority: high Keywords:

Created on 2003-02-19 23:17 by mark.dickinson, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (4)
msg14680 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2003-02-19 23:17
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 
 
msg14681 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-02-19 23:29
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)".
msg14682 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-02-20 03:45
Logged In: YES 
user_id=33168

Even though Tim gave me the rest of the year off, I'll take
a look. :-)  BTW, we all have access to a 64-bit box on the
SF compile farm. :-)  Mark, it would be great if you are
able to create a patch, but if not, I'll try to fix it.
msg14683 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-02-23 23:24
Logged In: YES 
user_id=33168

Thanks!  Checked in as:
 * Objects/longobject.c 1.156
 * Lib/test/test_types.py 1.46
 * Misc/NEWS 1.675
History
Date User Action Args
2022-04-10 16:06:55adminsetgithub: 38009
2003-02-19 23:17:40mark.dickinsoncreate