Skip to content

Commit 7fa7f33

Browse files
committed
product-mini/platforms/windows: mirror "Propagate WASI exit code" change
1 parent 36a1a37 commit 7fa7f33

File tree

1 file changed

+23
-8
lines changed
  • product-mini/platforms/windows

1 file changed

+23
-8
lines changed

product-mini/platforms/windows/main.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ app_instance_main(wasm_module_inst_t module_inst)
6363
wasm_application_execute_main(module_inst, app_argc, app_argv);
6464
if ((exception = wasm_runtime_get_exception(module_inst)))
6565
printf("%s\n", exception);
66-
return NULL;
66+
return exception;
6767
}
6868

6969
static void *
@@ -73,7 +73,7 @@ app_instance_func(wasm_module_inst_t module_inst, const char *func_name)
7373
app_argv + 1);
7474
/* The result of wasm function or exception info was output inside
7575
wasm_application_execute_func(), here we don't output them again. */
76-
return NULL;
76+
return wasm_runtime_get_exception(module_inst);
7777
}
7878

7979
/**
@@ -451,14 +451,29 @@ main(int argc, char *argv[])
451451
}
452452
#endif
453453

454-
if (is_repl_mode)
454+
ret = 0;
455+
if (is_repl_mode) {
455456
app_instance_repl(wasm_module_inst);
456-
else if (func_name)
457-
app_instance_func(wasm_module_inst, func_name);
458-
else
459-
app_instance_main(wasm_module_inst);
457+
}
458+
else if (func_name) {
459+
if (app_instance_func(wasm_module_inst, func_name)) {
460+
/* got an exception */
461+
ret = 1;
462+
}
463+
}
464+
else {
465+
if (app_instance_main(wasm_module_inst)) {
466+
/* got an exception */
467+
ret = 1;
468+
}
469+
}
460470

461-
ret = 0;
471+
#if WASM_ENABLE_LIBC_WASI != 0
472+
if (ret == 0) {
473+
/* propagate wasi exit code. */
474+
ret = wasm_runtime_get_wasi_exit_code(wasm_module_inst);
475+
}
476+
#endif
462477

463478
#if WASM_ENABLE_DEBUG_INTERP != 0
464479
fail4:

0 commit comments

Comments
 (0)