Skip to content

Commit

Permalink
KeyBuilder: use system byteorder to match numpy
Browse files Browse the repository at this point in the history
Closes gh-259
  • Loading branch information
inducer committed Aug 31, 2024
1 parent 6c1bd3f commit cee5027
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pytools/persistent_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ class KeyBuilder:
may stop working as early as 2022.
.. versionadded:: 2021.2
.. note::
Some key-building uses system byte order, so the built keys may not match
across different systems. It would be desirable to fix this, but this is
not yet done.
"""

# this exists so that we can (conceivably) switch algorithms at some point
Expand Down Expand Up @@ -280,7 +286,10 @@ def update_for_int(key_hash: Hash, key: int) -> None:
sz = 8
while True:
try:
key_hash.update(key.to_bytes(sz, byteorder="little", signed=True))
# Must match system byte order so that numpy and this
# generate the same string of bytes.
# https://github.com/inducer/pytools/issues/259
key_hash.update(key.to_bytes(sz, byteorder=sys.byteorder, signed=True))
return
except OverflowError:
sz *= 2
Expand Down

0 comments on commit cee5027

Please sign in to comment.