55_testcapi = import_helper .import_module ('_testcapi' )
66
77
8- SIZEOF_PY_HASH_T = _testcapi .SIZEOF_VOID_P
8+ SIZEOF_VOID_P = _testcapi .SIZEOF_VOID_P
9+ SIZEOF_PY_HASH_T = SIZEOF_VOID_P
910
1011
1112class CAPITest (unittest .TestCase ):
@@ -83,7 +84,7 @@ def test_hash_pointer(self):
8384 # Test PyHash_Pointer()
8485 hash_pointer = _testcapi .hash_pointer
8586
86- HASH_BITS = 8 * _testcapi . SIZEOF_VOID_P
87+ HASH_BITS = 8 * SIZEOF_VOID_P
8788 UHASH_T_MASK = ((2 ** HASH_BITS ) - 1 )
8889 HASH_T_MAX = (2 ** (HASH_BITS - 1 ) - 1 )
8990 MAX_PTR = UHASH_T_MASK
@@ -99,9 +100,17 @@ def uhash_to_hash(x):
99100 # Known values
100101 self .assertEqual (hash_pointer (0 ), 0 )
101102 self .assertEqual (hash_pointer (MAX_PTR ), - 2 )
102- self .assertEqual (hash_pointer (0xABCDEF1234567890 ),
103- 0x0ABCDEF123456789 )
104- self .assertEqual (hash_pointer (0x1234567890ABCDEF ),
105- uhash_to_hash (0xF1234567890ABCDE ))
106- self .assertEqual (hash_pointer (0xFEE4ABEDD1CECA5E ),
107- uhash_to_hash (0xEFEE4ABEDD1CECA5 ))
103+ if SIZEOF_VOID_P > 4 :
104+ self .assertEqual (hash_pointer (0xABCDEF1234567890 ),
105+ 0x0ABCDEF123456789 )
106+ self .assertEqual (hash_pointer (0x1234567890ABCDEF ),
107+ uhash_to_hash (0xF1234567890ABCDE ))
108+ self .assertEqual (hash_pointer (0xFEE4ABEDD1CECA5E ),
109+ uhash_to_hash (0xEFEE4ABEDD1CECA5 ))
110+ else :
111+ self .assertEqual (hash_pointer (0x12345678 ),
112+ uhash_to_hash (0x81234567 ))
113+ self .assertEqual (hash_pointer (0x1234ABCD ),
114+ uhash_to_hash (0xD1234ABC ))
115+ self .assertEqual (hash_pointer (0xDEADCAFE ),
116+ uhash_to_hash (0xEDEADCAF ))
0 commit comments