File tree Expand file tree Collapse file tree
tests/runtime-async/async/return-string Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //@ wasmtime-flags = '-Wcomponent-model-async'
2+
3+ package export_wit_world
4+
5+ import (
6+ "fmt"
7+ "runtime"
8+
9+ test "wit_component/my_test_i"
10+ )
11+
12+ /*
13+
14+ This tests for pinner leaks in generated Go code for async exported
15+ function that return heap-allocated types (strings, lists, etc.). Without
16+ `pinner.Unpin()`, the `runtime.Pinner` object goes out of scope after
17+ the function returns with pinned pointers still alive. When GC finalizes
18+ the Pinner, it panics:
19+
20+ ```
21+ panic: runtime error: runtime.Pinner: found leaking pinned pointer;
22+ forgot to call Unpin()?
23+ ```
24+ */
25+
26+ func Run () {
27+ // Perform a heap allocation
28+ got := test .ReturnString ()
29+ if got != "hello" {
30+ panic (fmt .Sprintf ("expected \" hello\" , got %q" , got ))
31+ }
32+
33+ // Force GC to finalize any leaked Pinners
34+ runtime .GC ()
35+ }
Original file line number Diff line number Diff line change 1+ package export_my_test_i
2+
3+ func ReturnString () string {
4+ return "hello"
5+ }
Original file line number Diff line number Diff line change 1+ package my : test ;
2+
3+ interface i {
4+ return-string : async func () -> string ;
5+ }
6+
7+ world test {
8+ export i ;
9+ }
10+
11+ world runner {
12+ import i ;
13+ export run : async func ();
14+ }
You can’t perform that action at this time.
0 commit comments