Commit Graph

1044 Commits

Author SHA1 Message Date
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
ca7fc908b5 chore(c-api) Update headers. 2021-01-28 09:23:56 +01:00
Ivan Enderlin
1828d8ecff Merge branch 'master' into fix-c-api-wasi-version 2021-01-28 09:18:30 +01:00
Ivan Enderlin
af5052598a chore(c-api) Update headers. 2021-01-28 09:15:25 +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
c03d61b78a test(c-api) Simplify wat2wasm test cases. 2021-01-28 09:11:50 +01:00
Nick Lewycky
95887af4da Include 'extern "C"' in our C header files when included in a C++ build. 2021-01-27 11:41:31 -08:00
bors[bot]
2d57f31037 Merge #2054
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>
2021-01-26 16:38:47 +00: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
79e55927b4 chore(c-api) Update headers. 2021-01-26 14:28:12 +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
361ea40042 chore(c-api) Update headers. 2021-01-26 13:19:20 +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
0c13314179 Add wasm_config_delete to the Wasm C API 2021-01-25 07:54:49 -08:00
Ivan Enderlin
70858eb201 feat(c-api) Do not build C headers if the env var DOCS_RS exists. 2021-01-22 14:22:28 +01:00
Syrus Akbary
e8344c56ae Fixed integration examples link 2021-01-20 14:48:13 -08:00
Mark McCaskey
924ffd8797 Prepare for 1.0.1 release 2021-01-12 08:08:19 -08:00
Mark McCaskey
bc73789cc0 Prepare for 1.0.0 release 2021-01-05 06:21:03 -08:00
Simon Warta
010f5fb597 Fix spelling Web Assembly -> WebAssembly 2021-01-03 22:01:26 +01:00
Simon Warta
82e9c0c18f Fix spelling WASM -> Wasm 2021-01-03 21:59:11 +01:00
Mark McCaskey
2d1c03bea0 Prepare for 1.0.0-rc1 release 2020-12-23 11:17:07 -08:00
Mark McCaskey
8724ed963d Merge branch 'master' into feature/multi-example-wasm-c-api 2020-12-21 07:51:28 -08:00
Mark McCaskey
89132dde61 Add _ back to unused variable 2020-12-18 14:52:52 -08:00
Mark McCaskey
9bc43c4d83 Revert wasmer_wasm.h to be correct 2020-12-18 14:41:52 -08:00
Mark McCaskey
800c6685e6 Ensure we print what the offending files are 2020-12-18 14:36:21 -08:00
Mark McCaskey
de0d78204b Merge branch 'master' into feature/assert-no-files-change-in-lint 2020-12-18 13:53:44 -08:00
Mark McCaskey
918554dd4c Assert that no files changed during lint 2020-12-18 12:56:35 -08:00
Mark McCaskey
cdf9825d62 Merge branch 'master' into feature/multi-example-wasm-c-api 2020-12-18 12:42:45 -08:00
Mark McCaskey
8025f8c1fa Make jit a default feature for wasmer-wasm-c-api 2020-12-18 09:51:15 -08:00
Ivan Enderlin
b9afb6e956 fix(c-api) Remove Box from wasm_functype_new. 2020-12-18 17:35:21 +01:00
Mark McCaskey
d44116251f Remove debug code from multi.c 2020-12-18 07:13:38 -08:00
Ivan Enderlin
2ca30fe634 fix(c-api) Ensure that uninitialized boxed vec are zeroed.
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.
2020-12-18 11:47:04 +01:00
Ivan Enderlin
40fa9c08c7 fix(c-api) UPdate wasm_functype_new according to previous commit. 2020-12-18 11:42:34 +01:00
Ivan Enderlin
a68a1e67f4 feat(c-api) Transmute boxed vecs to Vec<Option<Box<T>>> when deleting.
It's a safer way to handle partially uninitialized boxed vector, since
it protects against based deletion for every item.
2020-12-18 11:40:32 +01:00
Ivan Enderlin
51fe219efb feat(c-api) wasm_$name_vec_delete for boxed vec now takes an Option<&mut T>.
This was already the case for regular vec. This patch applies the same
pattern for boxed vec.

See deec77d2df.
2020-12-18 10:45:57 +01:00
Mark McCaskey
62663ab5e1 Get multi.c working in the Wasm C API 2020-12-17 14:35:55 -08:00
Ivan Enderlin
96169de8f0 test+doc(c-api) Improve test coverage for the macros module, and improve doc. 2020-12-17 14:57:07 +01:00
Ivan Enderlin
8aa08225cd feat(c-api) wasm_$name_vec_delete checks the vec is initialized.
In case of a boxed vector, `wasm_$name_vec_delete` now checks that the
vec is correctly initialized (by checking the first item only) because
transmuting `Vec<*mut T>` to `Vec<Box<T>>`, otherwise it will crash.
2020-12-17 14:55:29 +01:00
Ivan Enderlin
940dea72e7 feat(c-api) Simplify code by using new conversion implementations. 2020-12-17 14:17:50 +01:00
Ivan Enderlin
43026e651e feat(c-api) Implement From<&[T]> for wasm_$name_vec_t for boxed vec. 2020-12-17 14:17:17 +01:00
Ivan Enderlin
4abf6f81da fix(c-api) Fix how wasm_frame_t is implemented.
In `wasm.h`, `wasm_frame_t` is implemented with `WASM_DECLARE_TYPE`,
so with `WASM_DECLARE_VEC(frame, *)`. This `*` means the C struct for
the vector is defined:

```c
struct wasm_frame_vec_t {
    size_t size;
    wasm_frame_t** data;
}
```

The way we implement `wasm_frame_vec_t` in Rust is with the
`wasm_declare_vec!` macro. And it is wrong. We must use
`wasm_declared_boxed_vec!`.
2020-12-17 14:15:28 +01:00
Ivan Enderlin
a0c34fe850 fix(c-api) Fix how wasm_tabletype_t is implemented.
In `wasm.h`, `wasm_tabletype_t` is implemented with
`WASM_DECLARE_TYPE`, so with `WASM_DECLARE_VEC(tabletype, *)`. This
`*` means the C struct for the vector is defined:

```c
struct wasm_tabletype_vec_t {
    size_t size;
    wasm_tabletype_t** data;
}
```

The way we implement `wasm_tabletype_vec_t` in Rust is with the
`wasm_declare_vec!` macro. And it is wrong. We must use
`wasm_declared_boxed_vec!`.
2020-12-17 14:00:07 +01:00
Ivan Enderlin
a3c7a2d752 fix(c-api) Fix how wasm_memorytype_t is implemented.
In `wasm.h`, `wasm_memorytype_t` is implemented with
`WASM_DECLARE_TYPE`, so with `WASM_DECLARE_VEC(memorytype, *)`. This
`*` means the C struct for the vector is defined:

```c
struct wasm_memorytype_vec_t {
    size_t size;
    wasm_memorytype_t** data;
}
```

The way we implement `wasm_memorytype_vec_t` in Rust is with the
`wasm_declare_vec!` macro. And it is wrong. We must use
`wasm_declared_boxed_vec!`.
2020-12-17 13:58:26 +01:00
Ivan Enderlin
75ceb0d9e0 fix(c-api) Fix how wasm_globaltype_t is implemented.
In `wasm.h`, `wasm_globaltype_t` is implemented with
`WASM_DECLARE_TYPE`, so with `WASM_DECLARE_VEC(globaltype, *)`. This
`*` means the C struct for the vector is defined:

```c
struct wasm_globaltype_vec_t {
    size_t size;
    wasm_globaltype_t** data;
}
```

The way we implement `wasm_globaltype_vec_t` in Rust is with the
`wasm_declare_vec!` macro. And it is wrong. We must use
`wasm_declared_boxed_vec!`.
2020-12-17 13:56:48 +01:00
Ivan Enderlin
e10ad512bc fix(c-api) Fix how wasm_functype_t is implemented.
In `wasm.h`, `wasm_functype_t` is implemented with
`WASM_DECLARE_TYPE`, so with `WASM_DECLARE_VEC(functype, *)`. This `*`
means the C struct for the vector is defined:

```c
struct wasm_functype_vec_t {
    size_t size;
    wasm_functype_t** data;
}
```

The way we implement `wasm_functype_vec_t` in Rust is with the
`wasm_declare_vec!` macro. And it is wrong. We must use
`wasm_declared_boxed_vec!`.
2020-12-17 13:51:41 +01:00
Ivan Enderlin
a4effaaffe test+doc(c-api) Continue to improve test coverage of the C API. 2020-12-17 11:36:12 +01:00
bors[bot]
bc0ba32424 Merge #1947
1947: Include a NUL byte in the message returned by wasm_trap_message(). r=nlewycky a=nlewycky



Co-authored-by: Nick Lewycky <nick@wasmer.io>
2020-12-16 21:12:13 +00:00
Mark McCaskey
ef8bf91e6a Handle cross-compilation in c-api build.rs 2020-12-16 12:35:16 -08:00