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

@ -33,8 +33,13 @@ void check(bool success) {
}
void check_call(wasm_func_t* func, int i, wasm_val_t args[], int32_t expected) {
wasm_val_t results[1] = { WASM_INIT_VAL };
if (wasm_func_call(func, args, results) || results[0].of.i32 != expected) {
wasm_val_vec_t args_vec;
wasm_val_vec_t results_vec;
if (args)
wasm_val_vec_new(&args_vec, i, args);
wasm_val_vec_new(&results_vec, 1, (wasm_val_t []){ WASM_INIT_VAL });
if (wasm_func_call(func, args ? &args_vec : NULL, &results_vec)
|| results_vec.data[0].of.i32 != expected) {
printf("> Error on result\n");
exit(1);
}
@ -55,7 +60,9 @@ void check_call2(wasm_func_t* func, int32_t arg1, int32_t arg2, int32_t expected
}
void check_ok(wasm_func_t* func, int i, wasm_val_t args[]) {
if (wasm_func_call(func, args, NULL)) {
wasm_val_vec_t args_vec;
wasm_val_vec_new(&args_vec, i, args);
if (wasm_func_call(func, &args_vec, NULL)) {
printf("> Error on result, expected empty\n");
exit(1);
}
@ -67,8 +74,10 @@ void check_ok2(wasm_func_t* func, int32_t arg1, int32_t arg2) {
}
void check_trap(wasm_func_t* func, int i, wasm_val_t args[]) {
wasm_val_t results[1] = { WASM_INIT_VAL };
own wasm_trap_t* trap = wasm_func_call(func, args, results);
wasm_val_vec_t args_vec, results_vec;
wasm_val_vec_new(&args_vec, i, args);
wasm_val_vec_new(&results_vec, 1, (wasm_val_t []){ WASM_INIT_VAL });
own wasm_trap_t* trap = wasm_func_call(func, &args_vec, &results_vec);
if (! trap) {
printf("> Error on result, expected trap\n");
exit(1);