Skip to content

Instantly share code, notes, and snippets.

@pmp-p
Last active February 9, 2024 02:37
Show Gist options
  • Save pmp-p/e06d75b541ca38cc3f375ae5eb80a80e to your computer and use it in GitHub Desktop.
Save pmp-p/e06d75b541ca38cc3f375ae5eb80a80e to your computer and use it in GitHub Desktop.
gc orc/arc bug
#!/bin/bash
# wasi-sdk from https://github.com/WebAssembly/wasi-sdk/releases
# Nim git
PATH=/opt/wasi-sdk-21.0/bin:$PATH ./Nim/bin/nim \
--exceptions:goto \
--cc:clang -d:wasi --threads:off -d:emscripten --cpu:wasm32 \
--passC="-m32 -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_MMAN" \
--passL="-m32 -Wl,--export-all -mexec-model=reactor -lwasi-emulated-signal -lwasi-emulated-mman" \
-r c --out:out.wasi repro_inittable.nim
wasmtime --invoke setup $(pwd)/out.wasi
import std/tables
var
# initTable will crash on wasi
table = initTable[string, Table[int, proc () : void] ]()
# this will not
# table : Table[string, Table[int, proc () : void] ]
when defined(wasi):
proc initialize(argc: cint, args: ptr UncheckedArray[cstring], env: ptr UncheckedArray[cstring]): int {.importc: "main".}
proc setup() : void {.exportC:"setup".} =
when defined(wasi):
echo "_initialized"
discard initialize(0,nil,nil)
var
tcb : Table[int, proc () : void]
echo "begin"
tcb[1] = proc() = discard
var notused = table.mGetOrPut("hmm" , tcb )
echo "end"
# CRASH HERE
when not defined(wasi):
setup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment