diff --git a/core/iwasm/common/wasm_runtime_common.c b/core/iwasm/common/wasm_runtime_common.c index fb16aa0f3c..8f9f849cc2 100644 --- a/core/iwasm/common/wasm_runtime_common.c +++ b/core/iwasm/common/wasm_runtime_common.c @@ -2097,14 +2097,14 @@ wasm_runtime_get_export_global_inst(WASMModuleInstanceCommon *const module_inst, bool wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst, - char const *name, - wasm_table_inst_t *table_inst) + char const *name, wasm_table_inst_t out) { #if WASM_ENABLE_INTERP != 0 if (module_inst->module_type == Wasm_Module_Bytecode) { const WASMModuleInstance *wasm_module_inst = (const WASMModuleInstance *)module_inst; const WASMModule *wasm_module = wasm_module_inst->module; + uint32 i; for (i = 0; i < wasm_module->export_count; i++) { const WASMExport *wasm_export = &wasm_module->exports[i]; @@ -2112,11 +2112,9 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst, && !strcmp(wasm_export->name, name)) { const WASMTableInstance *wasm_table_inst = wasm_module_inst->tables[wasm_export->index]; - table_inst->elem_kind = - val_type_to_val_kind(wasm_table_inst->elem_type); - table_inst->cur_size = wasm_table_inst->cur_size; - table_inst->max_size = wasm_table_inst->max_size; - table_inst->elems = (void *)wasm_table_inst->elems; + + bh_memcpy_s(out, sizeof(WASMTableInstance), wasm_table_inst, + sizeof(WASMTableInstance)); return true; } } @@ -2127,6 +2125,7 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst, const AOTModuleInstance *aot_module_inst = (AOTModuleInstance *)module_inst; const AOTModule *aot_module = (AOTModule *)aot_module_inst->module; + uint32 i; for (i = 0; i < aot_module->export_count; i++) { const AOTExport *aot_export = &aot_module->exports[i]; @@ -2134,11 +2133,12 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst, && !strcmp(aot_export->name, name)) { const AOTTableInstance *aot_table_inst = aot_module_inst->tables[aot_export->index]; - table_inst->elem_kind = - val_type_to_val_kind(aot_table_inst->elem_type); - table_inst->cur_size = aot_table_inst->cur_size; - table_inst->max_size = aot_table_inst->max_size; - table_inst->elems = (void *)aot_table_inst->elems; + + bh_static_assert(sizeof(AOTTableInstance) + == sizeof(WASMTableInstance)); + + bh_memcpy_s(out, sizeof(WASMTableInstance), aot_table_inst, + sizeof(AOTTableInstance)); return true; } } @@ -2150,7 +2150,7 @@ wasm_runtime_get_export_table_inst(WASMModuleInstanceCommon *const module_inst, WASMFunctionInstanceCommon * wasm_table_get_func_inst(struct WASMModuleInstanceCommon *const module_inst, - const wasm_table_inst_t *table_inst, uint32_t idx) + const wasm_table_inst_t table_inst, uint32_t idx) { if (!table_inst) { bh_assert(0); diff --git a/core/iwasm/include/wasm_export.h b/core/iwasm/include/wasm_export.h index aa6cfaae75..870da90e6d 100644 --- a/core/iwasm/include/wasm_export.h +++ b/core/iwasm/include/wasm_export.h @@ -124,6 +124,10 @@ typedef WASMFunctionInstanceCommon *wasm_function_inst_t; struct WASMMemoryInstance; typedef struct WASMMemoryInstance *wasm_memory_inst_t; +/* Table instance */ +struct WASMTableInstance; +typedef struct WASMTableInstance *wasm_table_inst_t; + /* WASM section */ typedef struct wasm_section_t { struct wasm_section_t *next; @@ -315,15 +319,6 @@ typedef struct wasm_global_inst_t { void *global_data; } wasm_global_inst_t; -/* Table instance*/ -typedef struct wasm_table_inst_t { - wasm_valkind_t elem_kind; - uint32_t cur_size; - uint32_t max_size; - /* represents the elements of the table, for internal use only */ - void *elems; -} wasm_table_inst_t; - typedef enum { WASM_LOG_LEVEL_FATAL = 0, WASM_LOG_LEVEL_ERROR = 1, @@ -1711,7 +1706,7 @@ wasm_runtime_get_export_global_inst(const wasm_module_inst_t module_inst, WASM_RUNTIME_API_EXTERN bool wasm_runtime_get_export_table_inst(const wasm_module_inst_t module_inst, const char *name, - wasm_table_inst_t *table_inst); + wasm_table_inst_t table_inst); /** * Get a function instance from a table. @@ -1724,7 +1719,7 @@ wasm_runtime_get_export_table_inst(const wasm_module_inst_t module_inst, */ WASM_RUNTIME_API_EXTERN wasm_function_inst_t wasm_table_get_func_inst(const wasm_module_inst_t module_inst, - const wasm_table_inst_t *table_inst, uint32_t idx); + const wasm_table_inst_t table_inst, uint32_t idx); /** * Get attachment of native function from execution environment