Skip to content

Commit 6253bd1

Browse files
authored
Reduce the code duplication a bit (#4596)
This is a preparation for #4364 No functional changes are intended.
1 parent b36fac9 commit 6253bd1

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

core/iwasm/aot/aot_loader.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4226,15 +4226,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
42264226
#endif
42274227

42284228
#if WASM_ENABLE_LIBC_WASI != 0
4229-
#if WASM_ENABLE_UVWASI == 0
4230-
module->wasi_args.stdio[0] = os_invalid_raw_handle();
4231-
module->wasi_args.stdio[1] = os_invalid_raw_handle();
4232-
module->wasi_args.stdio[2] = os_invalid_raw_handle();
4233-
#else
4234-
module->wasi_args.stdio[0] = os_get_invalid_handle();
4235-
module->wasi_args.stdio[1] = os_get_invalid_handle();
4236-
module->wasi_args.stdio[2] = os_get_invalid_handle();
4237-
#endif /* WASM_ENABLE_UVWASI == 0 */
4229+
wasi_args_set_defaults(&module->wasi_args);
42384230
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
42394231

42404232
return module;

core/iwasm/common/wasm_runtime_common.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3438,6 +3438,21 @@ wasm_runtime_module_dup_data(WASMModuleInstanceCommon *module_inst,
34383438

34393439
#if WASM_ENABLE_LIBC_WASI != 0
34403440

3441+
void
3442+
wasi_args_set_defaults(WASIArguments *args)
3443+
{
3444+
memset(args, 0, sizeof(*args));
3445+
#if WASM_ENABLE_UVWASI == 0
3446+
args->stdio[0] = os_invalid_raw_handle();
3447+
args->stdio[1] = os_invalid_raw_handle();
3448+
args->stdio[2] = os_invalid_raw_handle();
3449+
#else
3450+
args->stdio[0] = os_get_invalid_handle();
3451+
args->stdio[1] = os_get_invalid_handle();
3452+
args->stdio[2] = os_get_invalid_handle();
3453+
#endif /* WASM_ENABLE_UVWASI == 0 */
3454+
}
3455+
34413456
static WASIArguments *
34423457
get_wasi_args_from_module(wasm_module_t module)
34433458
{

core/iwasm/common/wasm_runtime_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,9 @@ wasm_runtime_lookup_wasi_start_function(WASMModuleInstanceCommon *module_inst);
11181118
WASM_RUNTIME_API_EXTERN uint32_t
11191119
wasm_runtime_get_wasi_exit_code(WASMModuleInstanceCommon *module_inst);
11201120

1121+
void
1122+
wasi_args_set_defaults(WASIArguments *args);
1123+
11211124
bool
11221125
wasm_runtime_init_wasi(WASMModuleInstanceCommon *module_inst,
11231126
const char *dir_list[], uint32 dir_count,

core/iwasm/interpreter/wasm_loader.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6712,15 +6712,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
67126712
#endif
67136713

67146714
#if WASM_ENABLE_LIBC_WASI != 0
6715-
#if WASM_ENABLE_UVWASI == 0
6716-
module->wasi_args.stdio[0] = os_invalid_raw_handle();
6717-
module->wasi_args.stdio[1] = os_invalid_raw_handle();
6718-
module->wasi_args.stdio[2] = os_invalid_raw_handle();
6719-
#else
6720-
module->wasi_args.stdio[0] = os_get_invalid_handle();
6721-
module->wasi_args.stdio[1] = os_get_invalid_handle();
6722-
module->wasi_args.stdio[2] = os_get_invalid_handle();
6723-
#endif /* WASM_ENABLE_UVWASI == 0 */
6715+
wasi_args_set_defaults(&module->wasi_args);
67246716
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
67256717

67266718
(void)ret;

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3316,15 +3316,7 @@ create_module(char *name, char *error_buf, uint32 error_buf_size)
33163316
#endif
33173317

33183318
#if WASM_ENABLE_LIBC_WASI != 0
3319-
#if WASM_ENABLE_LIBC_UVWASI == 0
3320-
module->wasi_args.stdio[0] = os_invalid_raw_handle();
3321-
module->wasi_args.stdio[1] = os_invalid_raw_handle();
3322-
module->wasi_args.stdio[2] = os_invalid_raw_handle();
3323-
#else
3324-
module->wasi_args.stdio[0] = os_get_invalid_handle();
3325-
module->wasi_args.stdio[1] = os_get_invalid_handle();
3326-
module->wasi_args.stdio[2] = os_get_invalid_handle();
3327-
#endif /* WASM_ENABLE_UVWASI == 0 */
3319+
wasi_args_set_defaults(&module->wasi_args);
33283320
#endif /* WASM_ENABLE_LIBC_WASI != 0 */
33293321

33303322
(void)ret;

0 commit comments

Comments
 (0)