Update wasm_c_api to use vector types (#751)

The WASM C API now requires the use of vector types in certain apis.
Switching WAMR to use the new call signatures improves "drop in"
compilation compatibility between WAMR and other implementations
from a C-api embedding program's perspective.

* wasm_func_callback_t type has been updated to use wasm_val_vec_t
* wasm_func_callback_with_env_t type has been updated to use wasm_val_vec_t
* wasm_func_call() has been updated to use wasm_val_vec_t
* wasm_instance_new() has been updated to use wasm_extern_vec_t*
* wasm_instance_new_with_args() has been updated to use wasm_extern_vec_t*
* wasm_runtime_invoke_c_api_native() has been updated to support vector types
  in native callbacks without modifying the contract with the interpreter code.
* All users of the modified functions (including samples/wasm-c-api/src/*.c)
  have been appropriately updated.
This commit is contained in:
Saju Pillai
2021-09-15 23:54:25 -07:00
committed by GitHub
parent ed32693fc8
commit 76d641c7ea
13 changed files with 186 additions and 128 deletions

View File

@ -4104,6 +4104,7 @@ wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
wasm_val_t *params = params_buf, *results = results_buf;
wasm_trap_t *trap = NULL;
bool ret = false;
wasm_val_vec_t params_vec, results_vec;
if (func_type->param_count > 16
&& !(params = wasm_runtime_malloc(sizeof(wasm_val_t)
@ -4124,14 +4125,24 @@ wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
goto fail;
}
params_vec.data = params;
params_vec.num_elems = func_type->param_count;
params_vec.size = func_type->param_count;
params_vec.size_of_elem = sizeof(wasm_val_t);
results_vec.data = results;
results_vec.num_elems = 0;
results_vec.size = func_type->result_count;
results_vec.size_of_elem = sizeof(wasm_val_t);
if (!with_env) {
wasm_func_callback_t callback = (wasm_func_callback_t)func_ptr;
trap = callback(params, results);
trap = callback(&params_vec, &results_vec);
}
else {
wasm_func_callback_with_env_t callback =
(wasm_func_callback_with_env_t)func_ptr;
trap = callback(wasm_c_api_env, params, results);
trap = callback(wasm_c_api_env, &params_vec, &results_vec);
}
if (trap) {
@ -4155,7 +4166,7 @@ wasm_runtime_invoke_c_api_native(WASMModuleInstanceCommon *module_inst,
wasm_runtime_set_exception(module_inst, "unsupported result type");
goto fail;
}
results_vec.num_elems = func_type->result_count;
ret = true;
fail: