5
5
_testcapi = import_helper .import_module ('_testcapi' )
6
6
7
7
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
9
10
10
11
11
12
class CAPITest (unittest .TestCase ):
@@ -83,7 +84,7 @@ def test_hash_pointer(self):
83
84
# Test PyHash_Pointer()
84
85
hash_pointer = _testcapi .hash_pointer
85
86
86
- HASH_BITS = 8 * _testcapi . SIZEOF_VOID_P
87
+ HASH_BITS = 8 * SIZEOF_VOID_P
87
88
UHASH_T_MASK = ((2 ** HASH_BITS ) - 1 )
88
89
HASH_T_MAX = (2 ** (HASH_BITS - 1 ) - 1 )
89
90
MAX_PTR = UHASH_T_MASK
@@ -99,9 +100,17 @@ def uhash_to_hash(x):
99
100
# Known values
100
101
self .assertEqual (hash_pointer (0 ), 0 )
101
102
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