Skip to content

Commit

Permalink
wazevo: fixes FunctionDefinition index for listeners
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Mar 6, 2024
1 parent d89236b commit 8cd5507
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion experimental/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/experimental/opt"
"github.com/tetratelabs/wazero/experimental/wazerotest"
"github.com/tetratelabs/wazero/internal/testing/binaryencoding"
"github.com/tetratelabs/wazero/internal/testing/require"
Expand Down Expand Up @@ -73,7 +74,7 @@ func TestFunctionListenerFactory(t *testing.T) {
},
})

r := wazero.NewRuntime(ctx)
r := wazero.NewRuntimeWithConfig(ctx, opt.NewRuntimeConfigOptimizingCompiler())
defer r.Close(ctx) // This closes everything this Runtime created.

_, err := r.NewHostModuleBuilder("host").NewFunctionBuilder().WithFunc(func() {}).Export("").Instantiate(ctx)
Expand Down
4 changes: 2 additions & 2 deletions internal/engine/wazevo/call_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func (c *callEngine) callWithStack(ctx context.Context, paramResultStack []uint6
index := wasm.Index(stack[0])
mod := c.callerModuleInstance()
listener := mod.Engine.(*moduleEngine).listeners[index]
def := mod.Source.FunctionDefinition(index)
def := mod.Source.FunctionDefinition(index + mod.Source.ImportFunctionCount)
listener.Before(ctx, mod, def, stack[1:], c.stackIterator(false))
c.execCtx.exitCode = wazevoapi.ExitCodeOK
afterGoFunctionCallEntrypoint(c.execCtx.goCallReturnAddress, c.execCtxPtr,
Expand All @@ -369,7 +369,7 @@ func (c *callEngine) callWithStack(ctx context.Context, paramResultStack []uint6
index := wasm.Index(stack[0])
mod := c.callerModuleInstance()
listener := mod.Engine.(*moduleEngine).listeners[index]
def := mod.Source.FunctionDefinition(index)
def := mod.Source.FunctionDefinition(index + mod.Source.ImportFunctionCount)
listener.After(ctx, mod, def, stack[1:])
c.execCtx.exitCode = wazevoapi.ExitCodeOK
afterGoFunctionCallEntrypoint(c.execCtx.goCallReturnAddress, c.execCtxPtr,
Expand Down

0 comments on commit 8cd5507

Please sign in to comment.