-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(c-api) Handle initialized but empty results in wasm_func_call
#1783
Merged
bors
merged 11 commits into
wasmerio:master
from
Hywan:feat-c-api-func-call-with-initialized-results
Nov 2, 2020
Merged
feat(c-api) Handle initialized but empty results in wasm_func_call
#1783
bors
merged 11 commits into
wasmerio:master
from
Hywan:feat-c-api-func-call-with-initialized-results
Nov 2, 2020
Conversation
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
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.
Hywan
added
🎉 enhancement
New feature!
📦 lib-c-api
About wasmer-c-api
🧪 tests
I love tests
labels
Oct 30, 2020
Opened question: Do we need to error when the size of |
…lized-results-memory test(c-api) Enable the memory test example.
Hywan
commented
Oct 30, 2020
…b.com:Hywan/wasmer into feat-c-api-func-call-with-initialized-results
bors try |
tryBuild succeeded: |
jubianchi
approved these changes
Oct 30, 2020
bors r+ |
Build succeeded: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Our implementation of
wasm_func_call
was correct for C code asfollows:
However, for a C code such as:
the
vals
array were kept empty/unchanged. Why?Because
wasm_func_call
was replacing the value ofresults
by a newwasm_val_vec_t
. It is correct whenresults
is an empty vector, butit is incorrect when
results
is initialized with empty values.This patch tries to detect this pattern: If
results.data
isnull
,it means the vector is empty/uninitialized, and we can set a new
wasm_val_vec_t
, otherwise it means the vector is initialized withempty values, and we need to update each item individually.
This pattern can be found in the
global.c
example of the Wasm C API:wasmer/lib/c-api/tests/wasm_c_api/wasm-c-api/example/global.c
Lines 40 to 47 in 591691b
Without this patch, this test fails.
Review