2071: feat(c-api) Rename the `wasmer` module to `unstable` r=Hywan a=Hywan
# Description
This patch is the first step to prepare more unstable API (like cross-compilation etc.). Nothing changes for the moment from the user perspective, it's not a breaking change. It's just a reorganisation of the code, and better documentation. Basically the `wasmer_c_api::wasm_c_api::wasmer` module has been renamed `unstable`, so that it's super clear :-).
# Review
- [ ] ~Add a short description of the the change to the CHANGELOG.md file~ not necessary
Co-authored-by: Ivan Enderlin <ivan@mnt.io>
We use `VecDeque::drain` to read the captured stream, zipped with the
given buffer. We could expect that only the yielded items from the
`drain` will be removed, but actually no. Reading [the
documentation](https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.drain):
> Note 1: The element `range` is removed even if the iterator is not
> consumed until the end.
So by using a range like `..` will drain the entire captured stream,
whatever we read from it. Said differently, if the given buffer length
is smaller than the captured stream, the first read will drain the
entire captured stream.
This patch fixes the problem by specifying a better range:
`..min(inner_buffer.len(), oc.buffer.len())`.
With this new range, it's actually useless to increment
`num_bytes_written`, we already know ahead of time the amount of bytes
we are going to read. Consequently, the patch simplifies this code a
little bit more.
On Windows, using a `u32` representation for `wasi_version_t` fails if
a C++ compiler is used to treat a C program. So we change our strategy
here. We use a C representation to be FFI-safe, and the
`INVALID_VERSION` variant is now set to -1 instead of `u32::MAX`.
This patch also adds unit tests for `wasi_get_wasi_version` so that we
are sure of the behavior of this `type` on all platforms.
2054: Add `wasm_config_delete` to the Wasm C API r=MarkMcCaskey a=MarkMcCaskey
Fixes 1 missing import reported in #2052
This function is relatively new to the Wasm C API and its implementation is trivial
Co-authored-by: Mark McCaskey <mark@wasmer.io>
First, let's no longer derive from `Default` for `wasi_config_t`. By
default, we want to inherit `stdin`, `stdout` and `stderr`. The
default for `bool` is `false`; we want `true` here.
Second, let's update `wasi_config_new` to correctly set `inherit_*`
fields to `true`.
Third, lets' create `wasi_config_capture_*` functions. By default,
`std*` are inherited, so we need functions to capture them. That's the
new feature this patch introduces. The `wasi_config_inherit_*`
functions are kept for the sake of backward compatibility. Ideally, we
would want an API like `wasi_config_capture_*(capture: bool)`, but it
would duplicate the API somehow.
Fourth, let's fix `wasi_env_new`. We want to capture `stdout` and
`stderr` if and only if the `inherit_*` fields are set to
`false`. There was bug here. That's why everything was working
correctly by the way: `bool::default()` is `false`, and we have this
inverted condition here, so everything was working as expected because
of a double error. The only bug was that it wasn't possible to capture
`std*` before.
This patch updates how `wasm_$name_vec_new_uninitialized` creates the
vector. The vector is now fully allocated with `null` pointer for each
item, instead of having an empty vector with the initial capacity set
to `length`. That way, we are sure the vector is zeroed correctly.