Commit Graph

45 Commits

Author SHA1 Message Date
Ivan Enderlin
0826d3d722 Merge branch 'master' into feat-c-api-cross-compilation-2 2021-02-02 09:51:01 +01:00
Ivan Enderlin
b954429ca6 fix(c-api) Avoid more than one call to the function environment finalizer.
A function environment `WrapperEnv` can be cloned. In case the
original and the cloned environments are being dropped, the
`self.finalizer` function —if any— is called twice. That's a bug. It
must be called only once.

This patch updates the code to apply the finalizer only once by taking
it —if any— the first time it's called.
2021-02-01 15:42:28 +01:00
Ivan Enderlin
1eec258550 chore(c-api) Remove warning. 2021-01-29 14:25:47 +01:00
Mark McCaskey
8081aaeee4 Add WasmerEnv: Sync 2020-12-15 13:43:37 -08:00
Mark McCaskey
6a2116917f Fix up tests, make WasmerEnv: Send 2020-12-15 13:35:19 -08:00
Mark McCaskey
62d15fae36 Merge branch 'master' into fix/host-func-env-memory-leak 2020-12-15 08:37:18 -08:00
Simon Warta
8a8e8dc981 Avoid unnecessary &&wasmer::FunctionType 2020-12-14 13:32:42 +01:00
Mark McCaskey
ca4736cca9 Fix tests in C API and deprecated API 2020-12-04 17:40:37 -08:00
Mark McCaskey
de6cb9c4c4 Merge branch 'master' into feature/host-env-prototype 2020-11-20 15:54:35 -08:00
Mark McCaskey
52ef800c8f Use immutable env in the Wasm C API 2020-11-20 11:55:35 -08:00
Mark McCaskey
85169f6996 Add misc clean ups and corrections 2020-11-18 14:23:40 -08:00
Mark McCaskey
3580f165e8 Rename WasmerEnv::finish to WasmerEnv::init_with_instance 2020-11-17 17:14:11 -08:00
Mark McCaskey
a19705ae11 Remove free method, call finalizers in C API 2020-11-16 16:36:58 -08:00
Mark McCaskey
2690e5e8f6 Merge branch 'master' into feature/host-env-prototype 2020-11-16 15:13:29 -08:00
Ivan Enderlin
287084aa3e fix(c-api) Allow finalizer to be NULL. 2020-11-16 14:43:26 +01:00
Ivan Enderlin
5db1ab7c37 feat(c-api) More functions handle null pointers. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
e27ce51303 feat(c-api) wasm_func_call handles null pointers. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
b42c699be0 feat(c-api) Support null pointers in wasm_func_new_with_env. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
2735461caf feat(c-api) wasm_func_new supports null pointers for its arguments. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
c88886f09c Merge branch 'master' into test-c-api-inline-c-rs 2020-11-09 17:19:14 +01:00
Ivan Enderlin
adb84e2bf6 feat(c-api) Allow extern types to own data.
We have known memory leaks with extern types. The idea is to change
the code so that extern types can hold/own data. This patch does that.

A `wasm_externtype_t` holds a `WasmExternType` enum. This enum owns
sibling types such as `WasmFunctionType`, `WasmGlobalType`,
`WasmTableType` and `WasmMemoryType`. It is those structures that ows
the extern types data, like `params` and `results` as
`wasm_valtype_vec_t` for `WasmFunctionType`. That way, for example,
`wasm_functype_t` can return a pointer to these vec which it owns.

A `wasm_externtype_t` continues to be transmuted to `wasm_functype_t`
etc. Nothing changes on that side.
2020-11-09 15:04:22 +01:00
Ivan Enderlin
d2a5b8e101 chore(c-api) Use wasm_$name_vec_t::is_uninitialized(). 2020-10-30 14:16:00 +01:00
Ivan Enderlin
758bc9bb78 feat(c-api) Handle initialized but empty results in wasm_func_call.
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.
2020-10-30 13:41:02 +01:00
Mark McCaskey
78f958b52c Clean up misc code 2020-10-29 13:07:04 -07:00
Mark McCaskey
5b67b2f3dc Merge branch 'master' into feature/host-env-prototype 2020-10-27 16:24:00 -07:00
Ivan Enderlin
8d80befccd feat(c-api) Correctly implement “trap” in wasm_func_new*.
The implementation of “trap” in `wasm_func_new` was “incorrect”. It's
more idiomatic to return a `RuntimeError` than raising it in this
case, so that we don't duplicate locations where runtime errors are
raised.

The implementation of “trap” in `wasm_func_new_with_env` was
missing. This patch implements a similar strategy than the sibling
function.
2020-10-22 15:31:27 +02:00
Mark McCaskey
46204d6357 Fix up more tests 2020-10-21 12:00:30 -07:00
Ivan Enderlin
a73e457976 Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-19 08:01:00 +02:00
Ivan Enderlin
e29ea25dcd feat(c-api) Simplify code with unwrap_or_default. 2020-10-16 10:17:23 +02:00
Ivan Enderlin
2f692a1e2c fix(c-api) Fix merge issue. 2020-10-16 09:42:12 +02:00
Ivan Enderlin
ffff0441bc feat(c-api) Implement wasm_func_type.
This patch creates a `wasm_functype_t::new` constructor, that is used
by the new `wasm_func_type` function, and the existing
`wasm_functype_new_inner` function.
2020-10-15 15:05:26 +02:00
Ivan Enderlin
202ffe7771 fix(c-api) Fix wasm_func_call when params are empty.
`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.
2020-10-12 12:20:29 +02:00
Ivan Enderlin
e9cd710506 feat(c-api) Update wasm_func_call. 2020-10-12 11:25:17 +02:00
Ivan Enderlin
7f098387e8 faet(c-api) Update wasm_func_new_with_env. 2020-10-12 11:24:59 +02:00
Ivan Enderlin
5dffd976f5 feat(c-api) Update wasm_func_new. 2020-10-12 11:24:30 +02:00
Ivan Enderlin
d8dcb4133a feat(c-api) Update the definitions of wasm_func_callback*_t. 2020-10-12 11:23:52 +02: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
ae1a50b5d7 chore(c-api) Move cbindgen:ignore from functions/types to modules.
This patch removes the amount of `cbindgen:ignore` instructions by
moving this instruction onto the parent module.
2020-10-02 09:51:48 +02:00
Ivan Enderlin
ecb79e2af0 fix(c-api) Cherry-pick manually from https://github.com/wasmerio/wasmer/pull/1657. 2020-10-01 21:16:29 +02:00
Ivan Enderlin
8f627d9834 feat(c-api) Instruct cbindgen to ignore all functions and types defined in wasm.h. 2020-09-28 14:49:44 +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
7bb7684823 feat(c-api) Move value into its own module. 2020-09-24 09:06:37 +02:00
Ivan Enderlin
e7f06330c6 feat(c-api) Move function into its own module. 2020-09-24 08:56:28 +02:00