-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1783: feat(c-api) Handle initialized but empty results in `wasm_func_call` r=Hywan a=Hywan # Description Our implementation of `wasm_func_call` was correct for C code as follows: ```c wasm_val_vec_t arguments = WASM_EMPTY_VEC; wasm_val_vec_t results = WASM_EMPTY_VEC; wasm_func_call(func, &arguments, &results); ``` However, for a C code such as: ```c wasm_val_t vals[1]; wasm_val_vec_t arguments = WASM_EMPTY_VEC; wasm_val_vec_t results = WASM_ARRAY_VEC(vals); wasm_func_call(func, &arguments, &results); ``` the `vals` array were kept empty/unchanged. Why? Because `wasm_func_call` was replacing the value of `results` by a new `wasm_val_vec_t`. It is correct when `results` is an empty vector, but it is incorrect when `results` is initialized with empty values. This patch tries to detect this pattern: If `results.data` is `null`, it means the vector is empty/uninitialized, and we can set a new `wasm_val_vec_t`, otherwise it means the vector is initialized with empty values, and we need to update each item individually. This pattern can be found in the `global.c` example of the Wasm C API: https://github.com/wasmerio/wasmer/blob/591691bc17795e0f547a06bd8227ecc37f9aec39/lib/c-api/tests/wasm_c_api/wasm-c-api/example/global.c#L40-L47 Without this patch, this test fails. # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: Ivan Enderlin <[email protected]> Co-authored-by: jubianchi <[email protected]>
- Loading branch information
Showing
4 changed files
with
48 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters