[Python-bugs-list] [ python-Bugs-689659 ] 64-bit int and long hash keys incompatible

SourceForge.net noreply@sourceforge.net
Sun, 23 Feb 2003 15:24:47 -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: Closed
>Resolution: Fixed
Priority: 6
Submitted By: Mark Dickinson (marketdickinson)
Assigned to: Neal Norwitz (nnorwitz)
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: Neal Norwitz (nnorwitz)
Date: 2003-02-23 18:24

Message:
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

----------------------------------------------------------------------

Comment By: Neal Norwitz (nnorwitz)
Date: 2003-02-19 22:45

Message:
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.

----------------------------------------------------------------------

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