@@ -38,7 +38,7 @@ class Wasm3Engine final : public WasmEngine
3838
3939namespace
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
122123WasmEngine::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