Commit Graph

24 Commits

Author SHA1 Message Date
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
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
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
a4effaaffe test+doc(c-api) Continue to improve test coverage of the C API. 2020-12-17 11:36:12 +01:00
Ivan Enderlin
b8712437a4 doc(c-api) Update paste to 1.0 and document macros.
Thanks to https://github.com/dtolnay/paste/pull/48, we can generate
documentation with various tokens. It's so cool. Thanks @dtolnay!
2020-12-15 17:02:47 +01:00
Ivan Enderlin
f8935b3561 Merge branch 'master' into test-c-api 2020-12-10 16:01:14 +01:00
Mark McCaskey
deec77d2df Fix memory leak in wat2wasm function 2020-12-01 11:41:28 -08:00
Ivan Enderlin
25bcc9b7fc fixup 2020-12-01 15:29:41 +01:00
Ivan Enderlin
527b7061cc fix(c-api) Fix memory leak in wasm_$name_vec_delete.
This patch does several things:

1. It applies our Rust patterns for C API by replacing the raw pointer
   by `Option<Box<T>>`,
2. It allows `wasm_$name_vec_delete` to handle null pointer,
3. Because it takes ownership of the `wasm_$name_vec_t`, the pointer
   is correctly dropped (which fix the memory leak).
2020-12-01 14:25:59 +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
ede0420920 test(c-api) Free some wasm_valtype_vec_t. 2020-11-05 16:30:39 +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
77be1040f6 feat(c-api) Implement wasm_$name_vec_t::is_uninitialized(). 2020-10-30 14:11:09 +01:00
Ivan Enderlin
92e4cf64c1 feat(c-api) Implement wasm_$name_vec_t::into_slice_mut. 2020-10-30 13:29:28 +01:00
Mark McCaskey
e6c61c74ff Update boxed_vec to deal with boxed values 2020-10-02 16:33:03 -07:00
Mark McCaskey
34e6139570 Add conversion logic for boxed_vec, simplify vec creation code 2020-10-02 16:24:46 -07: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
1a0527af78 feat(c-api) Move all types into their own modules. 2020-09-24 11:41:04 +02:00
Ivan Enderlin
ebcd59de2b feat(c-api) Extract all macros into their own module. 2020-09-24 09:48:39 +02:00