diff --git a/Lib/test/test_capi/test_hash.py b/Lib/test/test_capi/test_hash.py index 574ff3dd3206c76..ace822ffafec213 100644 --- a/Lib/test/test_capi/test_hash.py +++ b/Lib/test/test_capi/test_hash.py @@ -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): @@ -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 @@ -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))