Refactor externref related APIs of reference types feature (#971)

Currently when calling wasm_runtime_call_wasm() to invoke wasm function
with externref type argument from runtime embedder, developer needs to
use wasm_externref_obj2ref() to convert externref obj into an internal ref
index firstly, which is not convenient to developer.
To align with GC feature in which all the references passed to
wasm_runtime_call_wasm() can be object pointers directly, we change the
interface of wasm_runtime_call_wasm() to allow to pass object pointer
directly for the externref argument, and refactor the related codes, update
the related samples and the document.
This commit is contained in:
Wenyong Huang
2022-01-19 11:25:08 +08:00
committed by GitHub
parent 2c743dbd51
commit 260d36a62d
30 changed files with 1148 additions and 595 deletions

View File

@ -66,9 +66,8 @@ int main(int argc, const char* argv[]) {
// Instantiate.
printf("Instantiating module...\n");
wasm_extern_vec_t imports;
wasm_extern_vec_new(&imports, 1, (wasm_extern_t* []) { wasm_func_as_extern(hello_func) });
wasm_extern_t* externs[] = { wasm_func_as_extern(hello_func) };
wasm_extern_vec_t imports = WASM_ARRAY_VEC(externs);
own wasm_instance_t* instance =
wasm_instance_new(store, module, &imports, NULL);
if (!instance) {
@ -98,7 +97,9 @@ int main(int argc, const char* argv[]) {
// Call.
printf("Calling export...\n");
if (wasm_func_call(run_func, NULL, NULL)) {
wasm_val_vec_t args = WASM_EMPTY_VEC;
wasm_val_vec_t results = WASM_EMPTY_VEC;
if (wasm_func_call(run_func, &args, &results)) {
printf("> Error calling function!\n");
return 1;
}
@ -114,4 +115,3 @@ int main(int argc, const char* argv[]) {
printf("Done.\n");
return 0;
}