Skip to content

Commit

Permalink
fix(stdlib): Fixed length and byteLength for strings over 2GiB. (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
cician authored Feb 5, 2022
1 parent c1695d0 commit 08a9487
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stdlib/string.gr
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 08a9487

Please sign in to comment.