Update WebAssembly C API submodule to latest commit. (#2579)

* Update WebAssembly C API submodule to latest commit.

This commit updates the WebAssembly C API submodule (for `wasm.h`) to the
latest commit out of master.

This fixes the behavior of `wasm_name_new_from_string` such that it no longer
copies the null character into the name, which caused unexpected failures when
using the Wasmtime linker as imports wouldn't resolve when the null was
present.

Along with this change were breaking changes to `wasm_func_call`, the host
callback signatures, and `wasm_instance_new` to take a vector type instead of a
pointer to an unsized array.

As a result, Wasmtime language bindings based on the C API will need to be
updated once this change is pulled in.

Fixes #2211.
Fixes #2131.

* Update Doxygen comments for wasm.h changes.
This commit is contained in:
Peter Huene
2021-01-14 07:36:12 -08:00
committed by GitHub
parent cde07b9a79
commit f94db6556c
19 changed files with 207 additions and 144 deletions

View File

@@ -54,10 +54,11 @@ void check(bool success) {
}
}
void check_call(wasm_func_t* func, wasm_val_t args[], size_t num_args, int32_t expected) {
void check_call(wasm_func_t* func, const wasm_val_vec_t* args_vec, int32_t expected) {
wasm_val_t results[1];
wasm_val_vec_t results_vec = WASM_ARRAY_VEC(results);
wasm_trap_t *trap = NULL;
wasmtime_error_t *error = wasmtime_func_call(func, args, num_args, results, 1, &trap);
wasmtime_error_t *error = wasmtime_func_call(func, args_vec, &results_vec, &trap);
if (error != NULL || trap != NULL)
exit_with_error("failed to call function", error, trap);
if (results[0].of.i32 != expected) {
@@ -67,42 +68,44 @@ void check_call(wasm_func_t* func, wasm_val_t args[], size_t num_args, int32_t e
}
void check_call0(wasm_func_t* func, int32_t expected) {
check_call(func, NULL, 0, expected);
wasm_val_vec_t args_vec = WASM_EMPTY_VEC;
check_call(func, &args_vec, expected);
}
void check_call1(wasm_func_t* func, int32_t arg, int32_t expected) {
wasm_val_t args[] = { {.kind = WASM_I32, .of = {.i32 = arg}} };
check_call(func, args, 1, expected);
wasm_val_t args[] = { WASM_I32_VAL(arg) };
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
check_call(func, &args_vec, expected);
}
void check_call2(wasm_func_t* func, int32_t arg1, int32_t arg2, int32_t expected) {
wasm_val_t args[2] = {
{.kind = WASM_I32, .of = {.i32 = arg1}},
{.kind = WASM_I32, .of = {.i32 = arg2}}
};
check_call(func, args, 2, expected);
wasm_val_t args[] = { WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) };
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
check_call(func, &args_vec, expected);
}
void check_ok(wasm_func_t* func, wasm_val_t args[], size_t num_args) {
void check_ok(wasm_func_t* func, const wasm_val_vec_t* args_vec) {
wasm_trap_t *trap = NULL;
wasmtime_error_t *error = wasmtime_func_call(func, args, num_args, NULL, 0, &trap);
wasm_val_vec_t results_vec = WASM_EMPTY_VEC;
wasmtime_error_t *error = wasmtime_func_call(func, args_vec, &results_vec, &trap);
if (error != NULL || trap != NULL)
exit_with_error("failed to call function", error, trap);
}
void check_ok2(wasm_func_t* func, int32_t arg1, int32_t arg2) {
wasm_val_t args[2] = {
{.kind = WASM_I32, .of = {.i32 = arg1}},
{.kind = WASM_I32, .of = {.i32 = arg2}}
};
check_ok(func, args, 2);
wasm_val_t args[] = { WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) };
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
check_ok(func, &args_vec);
}
void check_trap(wasm_func_t* func, wasm_val_t args[], size_t num_args, size_t num_results) {
wasm_val_t results[1];
void check_trap(wasm_func_t* func, const wasm_val_vec_t* args_vec, size_t num_results) {
assert(num_results <= 1);
wasm_val_t results[1];
wasm_val_vec_t results_vec;
results_vec.data = results;
results_vec.size = num_results;
wasm_trap_t *trap = NULL;
wasmtime_error_t *error = wasmtime_func_call(func, args, num_args, results, num_results, &trap);
wasmtime_error_t *error = wasmtime_func_call(func, args_vec, &results_vec, &trap);
if (error != NULL)
exit_with_error("failed to call function", error, NULL);
if (trap == NULL) {
@@ -113,16 +116,15 @@ void check_trap(wasm_func_t* func, wasm_val_t args[], size_t num_args, size_t nu
}
void check_trap1(wasm_func_t* func, int32_t arg) {
wasm_val_t args[1] = { {.kind = WASM_I32, .of = {.i32 = arg}} };
check_trap(func, args, 1, 1);
wasm_val_t args[] = { WASM_I32_VAL(arg) };
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
check_trap(func, &args_vec, 1);
}
void check_trap2(wasm_func_t* func, int32_t arg1, int32_t arg2) {
wasm_val_t args[2] = {
{.kind = WASM_I32, .of = {.i32 = arg1}},
{.kind = WASM_I32, .of = {.i32 = arg2}}
};
check_trap(func, args, 2, 0);
wasm_val_t args[] = { WASM_I32_VAL(arg1), WASM_I32_VAL(arg2) };
wasm_val_vec_t args_vec = WASM_ARRAY_VEC(args);
check_trap(func, &args_vec, 0);
}
int main(int argc, const char* argv[]) {
@@ -167,7 +169,8 @@ int main(int argc, const char* argv[]) {
printf("Instantiating module...\n");
wasm_instance_t* instance = NULL;
wasm_trap_t *trap = NULL;
error = wasmtime_instance_new(store, module, NULL, 0, &instance, &trap);
wasm_extern_vec_t imports = WASM_EMPTY_VEC;
error = wasmtime_instance_new(store, module, &imports, &instance, &trap);
if (!instance)
exit_with_error("failed to instantiate", error, trap);