diff --git a/extism_test.go b/extism_test.go index 1edd552..ffb543c 100644 --- a/extism_test.go +++ b/extism_test.go @@ -564,6 +564,15 @@ func TestVar(t *testing.T) { assert.Equal(t, expected, actual) } + + exit, _, err = plugin.Call("run_test", []byte{}) + + if assertCall(t, err, exit) { + actual := uintFromLEBytes(plugin.Var["a"]) + expected := uint(40) + + assert.Equal(t, expected, actual) + } } } @@ -619,14 +628,14 @@ func TestMultipleCallsOutput(t *testing.T) { return } - exit, output2, err := plugin.Call("count_vowels", []byte("bbb")) + exit, output2, err := plugin.Call("count_vowels", []byte("bbba")) if !assertCall(t, err, exit) { return } - assert.Equal(t, `{"count": 3}`, string(output1)) - assert.Equal(t, `{"count": 0}`, string(output2)) + assert.Equal(t, `{"count":3,"total":3,"vowels":"aeiouAEIOU"}`, string(output1)) + assert.Equal(t, `{"count":1,"total":4,"vowels":"aeiouAEIOU"}`, string(output2)) } } diff --git a/host.go b/host.go index da251bf..dbd2485 100644 --- a/host.go +++ b/host.go @@ -185,7 +185,10 @@ func (p *CurrentPlugin) ReadBytes(offset uint64) ([]byte, error) { return []byte{}, fmt.Errorf("Invalid memory block") } - return buffer, nil + cpy := make([]byte, len(buffer)) + copy(cpy, buffer) + + return cpy, nil } func buildHostModule(ctx context.Context, rt wazero.Runtime, name string, funcs []HostFunction) (api.Module, error) { diff --git a/wasm/count_vowels.wasm b/wasm/count_vowels.wasm index c5fe777..8a6c070 100644 Binary files a/wasm/count_vowels.wasm and b/wasm/count_vowels.wasm differ