Skip to content

Commit 7f3e0df

Browse files
authored
Handle a new scenario where an item is both exported and imported. (#3984)
1 parent 24ecee8 commit 7f3e0df

File tree

1 file changed

+118
-36
lines changed

1 file changed

+118
-36
lines changed

core/iwasm/common/wasm_runtime_common.c

+118-36
Original file line numberDiff line numberDiff line change
@@ -4266,31 +4266,68 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
42664266
export_type->kind = aot_export->kind;
42674267
switch (export_type->kind) {
42684268
case WASM_IMPORT_EXPORT_KIND_FUNC:
4269-
export_type->u.func_type =
4270-
(AOTFuncType *)aot_module
4271-
->types[aot_module->func_type_indexes
4272-
[aot_export->index
4273-
- aot_module->import_func_count]];
4269+
{
4270+
if (aot_export->index < aot_module->import_func_count) {
4271+
export_type->u.func_type =
4272+
(AOTFuncType *)aot_module
4273+
->import_funcs[aot_export->index]
4274+
.func_type;
4275+
}
4276+
else {
4277+
export_type->u.func_type =
4278+
(AOTFuncType *)aot_module
4279+
->types[aot_module->func_type_indexes
4280+
[aot_export->index
4281+
- aot_module->import_func_count]];
4282+
}
42744283
break;
4284+
}
42754285
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
4276-
export_type->u.global_type =
4277-
&aot_module
4278-
->globals[aot_export->index
4279-
- aot_module->import_global_count]
4280-
.type;
4286+
{
4287+
if (aot_export->index < aot_module->import_global_count) {
4288+
export_type->u.global_type =
4289+
&aot_module->import_globals[aot_export->index].type;
4290+
}
4291+
else {
4292+
export_type->u.global_type =
4293+
&aot_module
4294+
->globals[aot_export->index
4295+
- aot_module->import_global_count]
4296+
.type;
4297+
}
42814298
break;
4299+
}
42824300
case WASM_IMPORT_EXPORT_KIND_TABLE:
4283-
export_type->u.table_type =
4284-
&aot_module
4285-
->tables[aot_export->index
4286-
- aot_module->import_table_count]
4287-
.table_type;
4301+
{
4302+
if (aot_export->index < aot_module->import_table_count) {
4303+
export_type->u.table_type =
4304+
&aot_module->import_tables[aot_export->index]
4305+
.table_type;
4306+
}
4307+
else {
4308+
export_type->u.table_type =
4309+
&aot_module
4310+
->tables[aot_export->index
4311+
- aot_module->import_table_count]
4312+
.table_type;
4313+
}
42884314
break;
4315+
}
42894316
case WASM_IMPORT_EXPORT_KIND_MEMORY:
4290-
export_type->u.memory_type =
4291-
&aot_module->memories[aot_export->index
4292-
- aot_module->import_memory_count];
4317+
{
4318+
if (aot_export->index < aot_module->import_memory_count) {
4319+
export_type->u.memory_type =
4320+
&aot_module->import_memories[aot_export->index]
4321+
.mem_type;
4322+
}
4323+
else {
4324+
export_type->u.memory_type =
4325+
&aot_module
4326+
->memories[aot_export->index
4327+
- aot_module->import_memory_count];
4328+
}
42934329
break;
4330+
}
42944331
default:
42954332
bh_assert(0);
42964333
break;
@@ -4312,31 +4349,76 @@ wasm_runtime_get_export_type(WASMModuleCommon *const module, int32 export_index,
43124349
export_type->kind = wasm_export->kind;
43134350
switch (export_type->kind) {
43144351
case WASM_IMPORT_EXPORT_KIND_FUNC:
4315-
export_type->u.func_type =
4316-
wasm_module
4317-
->functions[wasm_export->index
4318-
- wasm_module->import_function_count]
4319-
->func_type;
4352+
{
4353+
if (wasm_export->index < wasm_module->import_function_count) {
4354+
export_type->u.func_type =
4355+
(WASMFuncType *)wasm_module
4356+
->import_functions[wasm_export->index]
4357+
.u.function.func_type;
4358+
}
4359+
else {
4360+
export_type->u.func_type =
4361+
wasm_module
4362+
->functions[wasm_export->index
4363+
- wasm_module->import_function_count]
4364+
->func_type;
4365+
}
4366+
43204367
break;
4368+
}
43214369
case WASM_IMPORT_EXPORT_KIND_GLOBAL:
4322-
export_type->u.global_type =
4323-
&wasm_module
4324-
->globals[wasm_export->index
4325-
- wasm_module->import_global_count]
4326-
.type;
4370+
{
4371+
if (wasm_export->index < wasm_module->import_global_count) {
4372+
export_type->u.global_type =
4373+
(WASMGlobalType *)&wasm_module
4374+
->import_globals[wasm_export->index]
4375+
.u.global.type;
4376+
}
4377+
else {
4378+
export_type->u.global_type =
4379+
&wasm_module
4380+
->globals[wasm_export->index
4381+
- wasm_module->import_global_count]
4382+
.type;
4383+
}
4384+
43274385
break;
4386+
}
43284387
case WASM_IMPORT_EXPORT_KIND_TABLE:
4329-
export_type->u.table_type =
4330-
&wasm_module
4331-
->tables[wasm_export->index
4332-
- wasm_module->import_table_count]
4333-
.table_type;
4388+
{
4389+
if (wasm_export->index < wasm_module->import_table_count) {
4390+
export_type->u.table_type =
4391+
(WASMTableType *)&wasm_module
4392+
->import_tables[wasm_export->index]
4393+
.u.table.table_type;
4394+
}
4395+
else {
4396+
export_type->u.table_type =
4397+
&wasm_module
4398+
->tables[wasm_export->index
4399+
- wasm_module->import_table_count]
4400+
.table_type;
4401+
}
4402+
43344403
break;
4404+
}
43354405
case WASM_IMPORT_EXPORT_KIND_MEMORY:
4336-
export_type->u.memory_type =
4337-
&wasm_module->memories[wasm_export->index
4338-
- wasm_module->import_memory_count];
4406+
{
4407+
if (wasm_export->index < wasm_module->import_memory_count) {
4408+
export_type->u.memory_type =
4409+
(WASMMemoryType *)&wasm_module
4410+
->import_memories[wasm_export->index]
4411+
.u.memory.mem_type;
4412+
}
4413+
else {
4414+
export_type->u.memory_type =
4415+
&wasm_module
4416+
->memories[wasm_export->index
4417+
- wasm_module->import_memory_count];
4418+
}
4419+
43394420
break;
4421+
}
43404422
default:
43414423
bh_assert(0);
43424424
break;

0 commit comments

Comments
 (0)