-
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) Update wasm-c-api
repository
#1699
Conversation
This change is important because `wasm.h` contains new functions, like `wasm_name_new_from_string_nt`, which are useful for the Go implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me...
we may need to update some of our own tests as well if any behavior has changed
@@ -94,6 +94,7 @@ Currently, known implementations of this API are included in | |||
* V8 natively (both C and C++) | |||
* Wabt (only C?) | |||
* Wasmtime (only C?) | |||
* [Wasmer](https://github.com/wasmerio/wasmer/tree/master/lib/c-api) (only C, C++ coming soon) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to this PR but I want to put this idea out into the universe before I forget:
When doing the release we have c-api/docs/deprecated
and we currently package that as README.md
in the C API that we distribute...
We should probably make a note that it's the deprecated API and file an issue to start building docs for Wasmer with the Wasm C API!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely!
The `CArrayIter` type is no longer needed. This patch removes it.
… so that it matches the definition of `wasm_instance_new`, which is much simpler and consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the updates required by the changes in wasm.h
, I've updated wasi/mod.rs
(the wasm_get_imports
function) to use a wasm_extern_vec_t
, so that it matches the definition of wasm_instance_new
, which is simpler and more consistent.
typedef own wasm_trap_t* (*wasm_func_callback_t)( | ||
const wasm_val_t args[], wasm_val_t results[]); | ||
const wasm_val_vec_t* args, own wasm_val_vec_t* results); | ||
typedef own wasm_trap_t* (*wasm_func_callback_with_env_t)( | ||
void* env, const wasm_val_t args[], wasm_val_t results[]); | ||
void* env, const wasm_val_vec_t* args, wasm_val_vec_t* results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust implementation updated ✅
WASM_API_EXTERN own wasm_trap_t* wasm_func_call( | ||
const wasm_func_t*, const wasm_val_t args[], wasm_val_t results[]); | ||
const wasm_func_t*, const wasm_val_vec_t* args, wasm_val_vec_t* results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust implementation updated ✅
WASM_API_EXTERN own wasm_instance_t* wasm_instance_new( | ||
wasm_store_t*, const wasm_module_t*, const wasm_extern_t* const imports[], | ||
wasm_store_t*, const wasm_module_t*, const wasm_extern_vec_t* imports, | ||
own wasm_trap_t** | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust implementation updated ✅
@MarkMcCaskey We must be very careful with the last update of
where
So basically, it creates a Why is it dangerous for us? Because our I don't know if we should change the behavior of |
All |
`wasm_$name_vec_t.into_slice` returns `None` if the vec is empty. So an empty vec of `wasm_extern_t` given to `wasm_func_call` was raising an error. This patch fixes this.
We must pass an empty array.
All good. All |
bors try |
tryBuild failed: |
|
||
let _traps = callback(*env, processed_args.as_ptr(), results.as_mut_ptr()); | ||
let _traps = callback(*env, &processed_args, &mut results); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might not be the same, we should be careful of the difference between fat pointers and thin pointers.
as_ptr
and as_mut_ptr
generally pass word sized pointers, references to slices are double words and references to vecs are different data entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed_args
and results
are now of kind wasm_val_vec_t
. I believe it is safe to use &
in this case.
bors try |
tryBuild failed: |
bors try |
tryBuild failed: |
bors try |
Windows will raise a warning because `clang++` is used to handle C code, so I previously add `-x c` to tell `clang++` to handle code as C code. Bbut if code is treated as C, it will fail because `static_assert` is not available for C on Windows. So let's live with the warning.
bors try- |
bors try |
tryBuild failed: |
bors try |
tryBuild succeeded: |
bors r+ |
Build succeeded: |
This change is important because
wasm.h
contains new functions, likewasm_name_new_from_string_nt
, which are useful for the Goimplementation.