From 08a948709270a9aa4ac853c2887bc652c4734f36 Mon Sep 17 00:00:00 2001 From: cician Date: Sat, 5 Feb 2022 15:51:25 +0100 Subject: [PATCH] fix(stdlib): Fixed length and byteLength for strings over 2GiB. (#1126) --- stdlib/string.gr | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/string.gr b/stdlib/string.gr index 4eea6430b9..530d4bc2da 100644 --- a/stdlib/string.gr +++ b/stdlib/string.gr @@ -9,6 +9,7 @@ import WasmI32 from "runtime/unsafe/wasmi32" import Memory from "runtime/unsafe/memory" import Exception from "runtime/exception" +import Conv from "runtime/unsafe/conv" import { tagSimpleNumber, allocateArray, @@ -76,7 +77,7 @@ export let rec length = (string: String) => { ptr = WasmI32.add(ptr, 1n) } - let ret = tagSimpleNumber(len) + let ret = Conv.wasmI32ToNumber(len) Memory.decRef(WasmI32.fromGrain(length)) Memory.decRef(WasmI32.fromGrain(string)) ret @@ -103,7 +104,7 @@ let wasmSafeLength = (s: String) => { @disableGC export let rec byteLength = (string: String) => { let string = WasmI32.fromGrain(string) - let ret = tagSimpleNumber(WasmI32.load(string, 4n)) + let ret = Conv.wasmI32ToNumber(WasmI32.load(string, 4n)) Memory.decRef(WasmI32.fromGrain(byteLength)) Memory.decRef(WasmI32.fromGrain(string)) ret