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:
@ -9,11 +9,11 @@
|
||||
|
||||
// A function to be called from Wasm code.
|
||||
own wasm_trap_t* neg_callback(
|
||||
const wasm_val_t args[], wasm_val_t results[]
|
||||
const wasm_val_vec_t* args, wasm_val_vec_t* results
|
||||
) {
|
||||
printf("Calling back...\n");
|
||||
results[0].kind = WASM_I32;
|
||||
results[0].of.i32 = -args[0].of.i32;
|
||||
results->data[0].kind = WASM_I32;
|
||||
results->data[0].of.i32 = -args->data[0].of.i32;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -49,18 +49,20 @@ void check_table(wasm_table_t* table, int32_t i, bool expect_set) {
|
||||
}
|
||||
|
||||
void check_call(wasm_func_t* func, int32_t arg1, int32_t arg2, int32_t expected) {
|
||||
wasm_val_t args[2] = { WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) };
|
||||
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, results;
|
||||
wasm_val_vec_new(&args, 2, (wasm_val_t []){ WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) });
|
||||
wasm_val_vec_new(&results, 1, (wasm_val_t []){ WASM_INIT_VAL });
|
||||
if (wasm_func_call(func, &args, &results) || results.data[0].of.i32 != expected) {
|
||||
printf("> Error on result\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void check_trap(wasm_func_t* func, int32_t arg1, int32_t arg2) {
|
||||
wasm_val_t args[2] = { WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) };
|
||||
wasm_val_t results[1] = { WASM_INIT_VAL };
|
||||
own wasm_trap_t* trap = wasm_func_call(func, args, results);
|
||||
wasm_val_vec_t args, results;
|
||||
wasm_val_vec_new(&args, 2, (wasm_val_t []){ WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) });
|
||||
wasm_val_vec_new(&results, 1, (wasm_val_t []){ WASM_INIT_VAL });
|
||||
own wasm_trap_t* trap = wasm_func_call(func, &args, &results);
|
||||
if (! trap) {
|
||||
printf("> Error on result, expected trap\n");
|
||||
exit(1);
|
||||
|
||||
Reference in New Issue
Block a user