Commit Graph

39 Commits

Author SHA1 Message Date
Ivan Enderlin
37aee2d7ad chore(c-api) Simplify code. 2021-02-01 12:03:38 +01:00
Ivan Enderlin
83c69a5623 feat(c-api) Implement From<String> for wasm_name_t. 2021-02-01 12:03:38 +01:00
Ivan Enderlin
18761cad7d feat(c-api) Implement wasm_extern_copy.
This patch also moves `wasm_extern_delete` into the correct Rust module.
2021-02-01 12:02:39 +01:00
Ivan Enderlin
5abac74618 feat(c-api) Rename wasm_named_extern_extern to wasm_named_extern_unwrap. 2021-02-01 12:02:12 +01:00
Ivan Enderlin
dc0cf7d4a4 feat(c-api) Implement wasi_get_unordered_imports. 2021-02-01 11:59:23 +01:00
Ivan Enderlin
277d85c5ae fix(c-api) Mark wasi_env_set_(instance|memory) as deprecated. 2021-02-01 11:55:38 +01:00
Ivan Enderlin
7f79fcc373 Merge branch 'master' into fix-c-api-wasi-read-captured-stream 2021-01-28 10:45:16 +01:00
Ivan Enderlin
ef1328e1d7 fix(c-api) Don't drain the entire captured stream when reading a small range.
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.
2021-01-28 10:28:49 +01:00
Ivan Enderlin
1828d8ecff Merge branch 'master' into fix-c-api-wasi-version 2021-01-28 09:18:30 +01:00
Ivan Enderlin
7a435ef740 feat(c-api) wasi_version_t has a C representation now.
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.
2021-01-28 09:12:10 +01:00
Ivan Enderlin
4688d9b369 chore(c-api) Disable wasi_config_capture_stdin for the moment`. 2021-01-26 16:21:55 +01:00
Ivan Enderlin
70c31068be fix(wasi) Fix the logic behind inherited/captured stdin, stdout and stderr.
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.
2021-01-26 14:12:48 +01:00
Ivan Enderlin
af2b8d5923 doc(c-api) Document wasi_version_t. 2021-01-26 13:19:04 +01:00
Ivan Enderlin
434285c0f9 fix(c-api) Use uppercase enum variants for constants of wasi_version_t. 2021-01-26 13:11:44 +01:00
Mark McCaskey
1cadf9af7f Fix unrelated warnings in Wasm C API 2020-12-01 12:09:21 -08:00
Ivan Enderlin
7973a965fb Merge branch 'master' into fix-vm-leak 2020-12-01 10:08:21 +01:00
Mark McCaskey
40eec3fbd6 Address feedback: misc clean ups 2020-11-25 14:19:29 -08:00
Ivan Enderlin
ca89bd5d75 feat(api) Rename Extern::from_export to …::from_vm_export.
I hope this little change will clarify a little bit that the `Export`
passed to `Extern::from_vm_export` is not a `wasmer::Export` but a
`wasmer_vm::Export`.
2020-11-19 11:06:18 +01:00
Mark McCaskey
46204d6357 Fix up more tests 2020-10-21 12:00:30 -07:00
Ivan Enderlin
d7d40e542f Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-16 10:18:46 +02:00
Ivan Enderlin
fea156defa feat(c-api) Update wasi_get_imports to use a wasm_extern_vec_t
… so that it matches the definition of `wasm_instance_new`, which is
much simpler and consistent.
2020-10-12 11:58:53 +02:00
Mark McCaskey
ba7b24f696 Add --dir and --mapdir support to native executable 2020-10-09 17:38:14 -07:00
Ivan Enderlin
3edcc89698 feat(c-api) Redefine wasm_store_t.
`wasm_store_t` is now a proper struct (rather than an opaque type) of
kind:

```rs
struct wasm_store_t {
    inner: Store
}
```

The rest of the patch updates the code accordingly.
2020-10-05 21:16:43 +02:00
Ivan Enderlin
a2854ebfea fix(c-api) Adjust cbindgen metadata for header files. 2020-10-01 21:20:13 +02:00
Nick Lewycky
9a3c5cf389 Remove extern "C" from a non-pub function that returns non-FFI'able type.
Add `extern "C"` to two `#[no_mangle] pub` functions.
2020-10-01 20:58:09 +02:00
Ivan Enderlin
d55b701e9d feat(c-api) Make wasi_config_t and wasi_env_t opaque structures.
Removing `repr(C)` make them opaque for cbindgen. Which is perfect for what we want.
2020-09-29 16:01:52 +02:00
Ivan Enderlin
174b03f4e9 feat(c-api) Use our fork of cbindgen.
Our fork contains incoming PR. It helps for example to skip struct
fields.
2020-09-24 16:15:04 +02:00
Ivan Enderlin
1a0527af78 feat(c-api) Move all types into their own modules. 2020-09-24 11:41:04 +02:00
Ivan Enderlin
44559a9f04 feat(c-api) Move as_extern APIs into the externals module. 2020-09-24 09:48:56 +02:00
Ivan Enderlin
50fbb9766d feat(c-api) Move instance into its own module. 2020-09-24 09:19:53 +02:00
Ivan Enderlin
bc664b011d feat(c-api) Move memory into its own module. 2020-09-22 17:21:19 +02:00
Mark McCaskey
8a9ac6ce59 Add helper function to get the start function 2020-08-12 18:03:57 -07:00
Mark McCaskey
cba35df3f1 Use wasi_env_set_instance instead of wasi_env_set_memory 2020-08-12 17:32:28 -07:00
Mark McCaskey
892fb4efcf Make caller responsible for allocation array for getting WASI imports 2020-08-12 17:08:58 -07:00
Mark McCaskey
2e36c8e63b Clean up and simplify API: explicit version no longer required 2020-08-12 13:09:58 -07:00
Mark McCaskey
5915cd9d3f Use circular buffer for stdout capture to reduce memory usage 2020-08-12 09:40:44 -07:00
Mark McCaskey
747cdd424a Try replacing wasi_state_builder_t with wasi_config_t
Experimenting to simplify our API.
2020-08-12 09:23:56 -07:00
Mark McCaskey
3919e435c4 Clean up WASI 'Wasm C API' API 2020-08-11 13:08:33 -07:00
Mark McCaskey
1211874f4a Implement WASI for the Wasm C API 2020-08-10 15:53:40 -07:00