Skip to content

Commit 46c1a3f

Browse files
committed
test: update wasm3 engine with new API
1 parent bc00683 commit 46c1a3f

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test/utils/wasm3_engine.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Wasm3Engine final : public WasmEngine
3838

3939
namespace
4040
{
41-
const void* env_adler32(IM3Runtime /*runtime*/, uint64_t* stack, void* mem)
41+
const void* env_adler32(IM3Runtime /*runtime*/, uint64_t* stack, void* mem, void* /*userdata*/)
4242
{
4343
const uint32_t offset = static_cast<uint32_t>(stack[0]);
4444
const uint32_t length = static_cast<uint32_t>(stack[1]);
@@ -115,20 +115,31 @@ std::optional<WasmEngine::FuncRef> Wasm3Engine::find_function(
115115
{
116116
IM3Function function;
117117
if (m3_FindFunction(&function, m_runtime, name.data()) == m3Err_none)
118+
// TODO: validate input/output types (m3_GetArgCount/m3_GetArgType/m3_GetRetCount/m3_GetRetType)
118119
return reinterpret_cast<WasmEngine::FuncRef>(function);
119120
return std::nullopt;
120121
}
121122

122123
WasmEngine::Result Wasm3Engine::execute(
123124
WasmEngine::FuncRef func_ref, const std::vector<uint64_t>& args)
124125
{
125-
unsigned ret_valid;
126-
uint64_t ret_value;
127126
IM3Function function = reinterpret_cast<IM3Function>(func_ref);
128-
auto const result = m3_CallProper(
129-
function, static_cast<uint32_t>(args.size()), args.data(), &ret_valid, &ret_value);
127+
128+
std::vector<const void*> argPtrs;
129+
for (auto const& arg : args)
130+
argPtrs.push_back(&arg);
131+
132+
// This ensures input count/type matches. For the return value we assume find_function did the validation.
133+
auto const result = m3_Call(function, static_cast<uint32_t>(args.size()), argPtrs.data());
130134
if (result == m3Err_none)
131-
return {false, ret_valid ? ret_value : std::optional<uint64_t>{}};
135+
{
136+
if (m3_GetRetCount(function) == 0)
137+
return {false, std::nullopt};
138+
139+
uint64_t ret_value = 0;
140+
assert(m3_GetResultsV(function, &ret_value) == m3Err_none);
141+
return {false, ret_value};
142+
}
132143
return {true, std::nullopt};
133144
}
134145
} // namespace fizzy::test

0 commit comments

Comments
 (0)