Skip to content

Commit ca33ed7

Browse files
committed
Add a more explicit check and an explanation comment to check.py
Apparently this package made it to platforms where the CPython internal hashing is neither Sip Hash 13 or 24. The comment should be enough to understand why the simple check.py smoke test fails there. Fixes #8.
1 parent 3984b3c commit ca33ed7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

check.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
import siphash24
77

88
# Python uses a randomized seed unless told otherwise
9-
assert int(os.environ['PYTHONHASHSEED']) == 0
9+
assert int(os.environ.get('PYTHONHASHSEED', '')) == 0
10+
11+
# Ensure that Python is built to use Sip Hash as internal hashing function.
12+
# The FNV hashing function is used on platforms that require aligned memory
13+
# access for integers. See PEP-456 for details
14+
algorithm = sys.hash_info.algorithm
15+
assert algorithm in {'siphash13', 'siphash24'}
1016

1117
# Python up to release 3.10 uses Sip Hash 13, Python 3.11 and later uses Sip Hash 13
12-
siphash = getattr(siphash24, sys.hash_info.algorithm)
18+
siphash = getattr(siphash24, algorithm)
1319

1420
DATA = b'spam'
1521

0 commit comments

Comments
 (0)