Skip to content

Commit

Permalink
Fix test on 32-bit
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Nov 15, 2023
1 parent 3a0752a commit 5b19577
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Lib/test/test_capi/test_hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
_testcapi = import_helper.import_module('_testcapi')


SIZEOF_PY_HASH_T = _testcapi.SIZEOF_VOID_P
SIZEOF_VOID_P = _testcapi.SIZEOF_VOID_P
SIZEOF_PY_HASH_T = SIZEOF_VOID_P


class CAPITest(unittest.TestCase):
Expand Down Expand Up @@ -83,7 +84,7 @@ def test_hash_pointer(self):
# Test PyHash_Pointer()
hash_pointer = _testcapi.hash_pointer

HASH_BITS = 8 * _testcapi.SIZEOF_VOID_P
HASH_BITS = 8 * SIZEOF_VOID_P
UHASH_T_MASK = ((2 ** HASH_BITS) - 1)
HASH_T_MAX = (2 ** (HASH_BITS - 1) - 1)
MAX_PTR = UHASH_T_MASK
Expand All @@ -99,9 +100,17 @@ def uhash_to_hash(x):
# Known values
self.assertEqual(hash_pointer(0), 0)
self.assertEqual(hash_pointer(MAX_PTR), -2)
self.assertEqual(hash_pointer(0xABCDEF1234567890),
0x0ABCDEF123456789)
self.assertEqual(hash_pointer(0x1234567890ABCDEF),
uhash_to_hash(0xF1234567890ABCDE))
self.assertEqual(hash_pointer(0xFEE4ABEDD1CECA5E),
uhash_to_hash(0xEFEE4ABEDD1CECA5))
if SIZEOF_VOID_P > 4:
self.assertEqual(hash_pointer(0xABCDEF1234567890),
0x0ABCDEF123456789)
self.assertEqual(hash_pointer(0x1234567890ABCDEF),
uhash_to_hash(0xF1234567890ABCDE))
self.assertEqual(hash_pointer(0xFEE4ABEDD1CECA5E),
uhash_to_hash(0xEFEE4ABEDD1CECA5))
else:
self.assertEqual(hash_pointer(0x12345678),
uhash_to_hash(0x81234567))
self.assertEqual(hash_pointer(0x1234ABCD),
uhash_to_hash(0xD1234ABC))
self.assertEqual(hash_pointer(0xDEADCAFE),
uhash_to_hash(0xEDEADCAF))

0 comments on commit 5b19577

Please sign in to comment.