From 029059fbeed185a2e467a014bbc313fda4b87c5e Mon Sep 17 00:00:00 2001 From: Oscar Spencer Date: Sat, 2 Mar 2024 14:06:42 -0600 Subject: [PATCH] fix(stdlib): Ensure consistent marshal representation (#2045) Co-authored-by: Blaine Bublitz --- compiler/test/stdlib/marshal.test.gr | 2 ++ stdlib/marshal.gr | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/test/stdlib/marshal.test.gr b/compiler/test/stdlib/marshal.test.gr index 1c3488f02..e687ace90 100644 --- a/compiler/test/stdlib/marshal.test.gr +++ b/compiler/test/stdlib/marshal.test.gr @@ -91,3 +91,5 @@ let truncatedRecord = Bytes.slice( ) ) assert Result.isErr(unmarshal(truncatedRecord)) + +assert Marshal.marshal("🌾") == Marshal.marshal("🌾") diff --git a/stdlib/marshal.gr b/stdlib/marshal.gr index c8f448206..8c088a1f8 100644 --- a/stdlib/marshal.gr +++ b/stdlib/marshal.gr @@ -423,8 +423,11 @@ let marshal = (value, buf) => { @unsafe provide let marshal = value => { let valuePtr = fromGrain(value) - let buf = allocateBytes(size(valuePtr)) + let size = size(valuePtr) + let buf = allocateBytes(size) + Memory.fill(buf + 8n, 0n, size) marshal(valuePtr, buf + 8n) + ignore(value) toGrain(buf): Bytes }