diff options
author | polwex <polwex@sortug.com> | 2025-10-07 00:14:45 +0700 |
---|---|---|
committer | polwex <polwex@sortug.com> | 2025-10-07 00:14:45 +0700 |
commit | 799007bbfee05ee706a9d24d399458c2229ad6af (patch) | |
tree | 8050c77f745cfdcbdd34aead8f41bcfc2053b118 /ocaml | |
parent | 5242ee845cdb3a7e9780443bf5d7e534f72c3f28 (diff) |
and he fixed the mugs
Diffstat (limited to 'ocaml')
-rw-r--r-- | ocaml/lib/noun.ml | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ocaml/lib/noun.ml b/ocaml/lib/noun.ml index f4c4f87..382c79d 100644 --- a/ocaml/lib/noun.ml +++ b/ocaml/lib/noun.ml @@ -182,9 +182,15 @@ let rec mug noun = end and compute_mug_atom z = - (* Convert to bytes (little-endian, strip trailing zeros) *) + (* Convert to bytes (little-endian) *) let bytes = Z.to_bits z in - mug_bytes_with_seed bytes 0xcafebabel + (* Strip trailing zeros like C's u3r_mug_words does *) + let len = ref (String.length bytes) in + while !len > 0 && bytes.[!len - 1] = '\x00' do + decr len + done; + let stripped = String.sub bytes 0 !len in + mug_bytes_with_seed stripped 0xcafebabel (** Pretty-print a noun *) let rec pp_noun fmt = function |