From 7b84046d79e48f801deba929f20170479acbc0e8 Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Fri, 22 Dec 2023 13:47:36 -0500 Subject: [PATCH] fix: add input_offset --- extism_test.go | 15 +++++++++++++++ host.go | 1 + wasm/input_offset.wasm | Bin 0 -> 318 bytes 3 files changed, 16 insertions(+) create mode 100644 wasm/input_offset.wasm diff --git a/extism_test.go b/extism_test.go index 6c0e8ba..bb4ee75 100644 --- a/extism_test.go +++ b/extism_test.go @@ -701,6 +701,21 @@ func TestJsonManifest(t *testing.T) { } } +func TestInputOffset(t *testing.T) { + manifest := manifest("input_offset.wasm") + + if plugin, ok := plugin(t, manifest); ok { + defer plugin.Close() + + input_data := []byte("hello world") + exit, output, err := plugin.Call("input_offset_length", input_data) + + if assertCall(t, err, exit) { + assert.Equal(t, len(input_data), int(output[0])) + } + } +} + func BenchmarkInitialize(b *testing.B) { ctx := context.Background() cache := wazero.NewCompilationCache() diff --git a/host.go b/host.go index 31cd6cd..c99c739 100644 --- a/host.go +++ b/host.go @@ -256,6 +256,7 @@ func buildEnvModule(ctx context.Context, rt wazero.Runtime, extism api.Module) ( wrap("input_set", []ValueType{ValueTypeI64, ValueTypeI64}, []ValueType{}) wrap("output_set", []ValueType{ValueTypeI64, ValueTypeI64}, []ValueType{}) wrap("input_length", []ValueType{}, []ValueType{ValueTypeI64}) + wrap("input_offset", []ValueType{}, []ValueType{ValueTypeI64}) wrap("output_length", []ValueType{}, []ValueType{ValueTypeI64}) wrap("output_offset", []ValueType{}, []ValueType{ValueTypeI64}) wrap("length", []ValueType{ValueTypeI64}, []ValueType{ValueTypeI64}) diff --git a/wasm/input_offset.wasm b/wasm/input_offset.wasm new file mode 100644 index 0000000000000000000000000000000000000000..163adce509d225ba6de9e1d80ba0563d0a256e66 GIT binary patch literal 318 zcmZY4Jqp4=5Cz~jv)QOoFkmMZ@dP$%VW*v^h(XpL$Yv$G5pCAqQyWoGV>2*3hW8CJ zs|f%Nf(^)T$k&6tN4?$nPO`5q?r8PmV62;{;@mqHr^=;fx3kIt%{a_ev3CbhGw4`n zN|jdgDY%)*EYHpM|0Xh(dzL+$STG4GYHKUuP%CZ9D`W7jN#ETv8qtu*uiCK~BSDOq kVop%+!4h4pgCf(4W)eTo(A&-*s(8tQF9>%@62h140m`vjSO5S3 literal 0 HcmV?d00001