Skip to content

Commit

Permalink
Fix short_hash for big endian plaform (mirage#1505)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoguey committed Aug 26, 2021
1 parent 24966c7 commit d768436
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,8 @@
- `Tree` operations now raise a `Dangling_hash` exception when called with a
path that contains dangling hashes in the underlying store, rather than
interpreting such paths as ending with empty nodes (#1477, @CraigFe)
- Fix the pre-hashing function for big-endian architectures. (#1505,
@Ngoguey42, @dinosaure)

### Added

Expand Down
6 changes: 5 additions & 1 deletion src/irmin/hash.ml
Expand Up @@ -20,8 +20,12 @@ module Make (H : Digestif.S) = struct
type t = H.t

external get_64 : string -> int -> int64 = "%caml_string_get64u"
external swap64 : int64 -> int64 = "%bswap_int64"

let short_hash c = Int64.to_int (get_64 (H.to_raw_string c) 0)
let get_64_little_endian str idx =
if Sys.big_endian then swap64 (get_64 str idx) else get_64 str idx

let short_hash c = Int64.to_int (get_64_little_endian (H.to_raw_string c) 0)
let hash_size = H.digest_size

let of_hex s =
Expand Down

0 comments on commit d768436

Please sign in to comment.