@@ -591,21 +591,28 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
591591 }
592592
593593 *function = [func, function_name, this ](ContextBase *context, Args... args) -> void {
594- wasm_val_vec_t params;
594+ const bool log = cmpLogLevel (LogLevel::trace);
595+ SaveRestoreContext saved_context (context);
596+ wasm_val_vec_t results = WASM_EMPTY_VEC;
597+ WasmTrapPtr trap;
598+
599+ // Workaround for MSVC++ not supporting zero-sized arrays.
595600 if constexpr (sizeof ...(args) > 0 ) {
596601 wasm_val_t params_arr[] = {makeVal (args)...};
597- params = WASM_ARRAY_VEC (params_arr);
602+ wasm_val_vec_t params = WASM_ARRAY_VEC (params_arr);
603+ if (log) {
604+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
605+ printValues (¶ms) + " )" );
606+ }
607+ trap.reset (wasm_func_call (func, ¶ms, &results));
598608 } else {
599- params = WASM_EMPTY_VEC;
600- }
601- wasm_val_vec_t results = WASM_EMPTY_VEC;
602- const bool log = cmpLogLevel (LogLevel::trace);
603- if (log) {
604- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" + printValues (¶ms) +
605- " )" );
609+ wasm_val_vec_t params = WASM_EMPTY_VEC;
610+ if (log) {
611+ integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
612+ }
613+ trap.reset (wasm_func_call (func, ¶ms, &results));
606614 }
607- SaveRestoreContext saved_context (context);
608- WasmTrapPtr trap{wasm_func_call (func, ¶ms, &results)};
615+
609616 if (trap) {
610617 WasmByteVec error_message;
611618 wasm_trap_message (trap.get (), error_message.get ());
@@ -645,22 +652,29 @@ void Wasmtime::getModuleFunctionImpl(std::string_view function_name,
645652 }
646653
647654 *function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
648- wasm_val_vec_t params;
655+ const bool log = cmpLogLevel (LogLevel::trace);
656+ SaveRestoreContext saved_context (context);
657+ wasm_val_t results_arr[1 ];
658+ wasm_val_vec_t results = WASM_ARRAY_VEC (results_arr);
659+ WasmTrapPtr trap;
660+
661+ // Workaround for MSVC++ not supporting zero-sized arrays.
649662 if constexpr (sizeof ...(args) > 0 ) {
650663 wasm_val_t params_arr[] = {makeVal (args)...};
651- params = WASM_ARRAY_VEC (params_arr);
664+ wasm_val_vec_t params = WASM_ARRAY_VEC (params_arr);
665+ if (log) {
666+ integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
667+ printValues (¶ms) + " )" );
668+ }
669+ trap.reset (wasm_func_call (func, ¶ms, &results));
652670 } else {
653- params = WASM_EMPTY_VEC;
654- }
655- wasm_val_t results_arr[1 ];
656- wasm_val_vec_t results = WASM_ARRAY_VEC (results_arr);
657- const bool log = cmpLogLevel (LogLevel::trace);
658- if (log) {
659- integration ()->trace (" [host->vm] " + std::string (function_name) + " (" + printValues (¶ms) +
660- " )" );
671+ wasm_val_vec_t params = WASM_EMPTY_VEC;
672+ if (log) {
673+ integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
674+ }
675+ trap.reset (wasm_func_call (func, ¶ms, &results));
661676 }
662- SaveRestoreContext saved_context (context);
663- WasmTrapPtr trap{wasm_func_call (func, ¶ms, &results)};
677+
664678 if (trap) {
665679 WasmByteVec error_message;
666680 wasm_trap_message (trap.get (), error_message.get ());
0 commit comments