Commit Graph

1044 Commits

Author SHA1 Message Date
Ivan Enderlin
19cc55fb0d doc(c-api) Add another possible Rust pattern 2020-11-16 10:49:37 +01:00
Ivan Enderlin
ee71166f65 doc(c-api) Remove the // own inline doc. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
3df35e1aff fix(c-api) Fix memory leak in wasm_functype_new.
`wasm_functype_new` takes the ownership of `params` and `results`. By
using `Box`, we are sure they are dropped correctly inside the
function.
2020-11-16 10:49:37 +01:00
Ivan Enderlin
84d807716e doc(c-api) Add Dvelopment Notes. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
8ef36491d4 fix(c-api) wasm_exporttype_t owns its data. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
f3a542eb8c doc(c-api) Remove an outdated comment. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
d7bcf0442a fix(c-api) Correctly drop wasm_importtype_vec_t from wasm_module_imports. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
cc04d67263 fix(c-api) Fix a segfault and detect a new memory leak. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
4ab83ed545 fix(c-api) Remove TODO for From<&ImportType> for wasm_importtype_t.
A `String` is a `Vec<u8>` by definition, nothing more. Freeing one is
like freeing another.
2020-11-16 10:49:37 +01:00
Ivan Enderlin
8bdfad18d1 fix(c-api) wasm_importtype_t _owns_ its fields.
The `wasm.h` file defines `wasm_importtype_new` to take ownership of
the module, the name, and the extern type. This patch thus changes
`NonNull` to `Box` for those types.

`wasm_importtype_new` also handles null pointer with `Option<Box<T>>`
and returns an `Option<Box<T>>`.

The rest of the code is simplified. The patch fixes also some typos in
variable namings.
2020-11-16 10:49:37 +01:00
Ivan Enderlin
9635e43c08 fix(c-api) Remove the memory leak in wasm_tabletype_element. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
7212ab45fd fix(c-api) Remove memory leaks with wasm_tabletype_limits. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
1604999595 fix(c-api) Remove memory leak with wasm_globaltype_content. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
598c4cc276 fix(c-api) Remove memory leak with wasm_memorytype_limits. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
f49a10411e chore(c-api) Return references instead of pointers. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
7b727ccffe chore(c-api) Remove a warning by commenting an unreachable code. 2020-11-16 10:49:37 +01:00
Ivan Enderlin
cf9b1018c1 fix(c-api) Use the newly release of inline-c-rs. 2020-11-16 10:11:01 +01:00
jubianchi
96a0d73ef8 fix(c-api): Remove the use of to link to Wasmer C API. 2020-11-13 21:09:04 +01:00
Ivan Enderlin
458daebe8c fix(c-api) Add -rpath to the linker only on Linux. 2020-11-13 17:04:10 +01:00
Ivan Enderlin
7cfd2ad161 fix(c-api) Use latest version of inline-c-rs and fix rpath on Linux. 2020-11-13 15:23:21 +01:00
Ivan Enderlin
7c363ea451 test(c-api) Fix segfault. 2020-11-10 10:57:47 +01:00
Ivan Enderlin
5bbfc54757 chore(c-api) Run clang-format. 2020-11-10 10:53:20 +01:00
Ivan Enderlin
3c3c033cbd chore(c-api) Fix CS. 2020-11-10 10:51:18 +01:00
Ivan Enderlin
3b9e045259 test(c-api) Free wat and prevent failure in assert. 2020-11-10 10:49:20 +01:00
Ivan Enderlin
d6cd8c6d94 test(c-api) Use wasm_externtype_as_*_const. 2020-11-10 10:42:44 +01:00
Ivan Enderlin
4d81f9a27e chore(c-api) Fix CS. 2020-11-10 10:42:24 +01:00
Ivan Enderlin
6459f02154 Merge branch 'test-c-api-inline-c-rs' of github.com:Hywan/wasmer into test-c-api-inline-c-rs 2020-11-10 10:32:35 +01:00
Ivan Enderlin
f63dc943cc doc(c-api) Update and fix Doxygen. 2020-11-10 10:31:54 +01:00
Ivan Enderlin
75fba28702 Update lib/c-api/tests/wasmer_wasm.h
Co-authored-by: nlewycky <nicholas@mxc.ca>
2020-11-09 20:05:57 +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
a34600a3ad doc(c-api) Build the new Wasm C API. 2020-11-09 17:12:42 +01:00
Ivan Enderlin
d4809527f9 fix(c-api) Fix memory leaks with extern types. 2020-11-09 17:12:09 +01:00
Ivan Enderlin
47b8d289b4 test(c-api) Assert wasm_name_t has the expected size. 2020-11-09 16:24:46 +01:00
Ivan Enderlin
69e1b7ccc0 test(c-api) Rollback: Use assert intead of wasmer_assert. 2020-11-09 15:55:31 +01:00
Ivan Enderlin
637862dcdc test(c-api) Enable debug mode for C tests. 2020-11-09 15:45:17 +01:00
Ivan Enderlin
8e4ca4ee34 chore(c-api) Rename a parameter. 2020-11-09 15:28:45 +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
Nick Lewycky
49b0a4a16a Prepare for 1.0.0-alpha5 release. 2020-11-06 11:50:07 -08:00
Ivan Enderlin
19fe6e482c test(c-api) _wasmer_assert_fail must exit the program. 2020-11-06 15:09:20 +01:00
Ivan Enderlin
5bef2462dc doc(c-api) Write tested C examples for wasm_module_new. 2020-11-06 12:01:50 +01:00
Ivan Enderlin
55b2b88524 test(c-api) Declare a wasmer_assert_name helper. 2020-11-06 11:17:55 +01:00
Ivan Enderlin
8fdf928847 test(c-api) Rename our helper wasm_byte_vec_new_from_string to wasmer_…. 2020-11-06 10:16:25 +01:00
Ivan Enderlin
ab4de3f86d test(c-api) Use wasmer_assert rather than assert. 2020-11-06 09:40:32 +01:00
Ivan Enderlin
33a2651bab test(c-api) Implement wasmer_assert.
`assert.h` does nothing when the code is compiled in release
mode. That's not what we want :-). Let's reimplement `assert` as
`wasmer_assert`, which is close to the original `assert` function.
2020-11-06 09:39:12 +01:00
Ivan Enderlin
8009fea945 test(c-api) Include string.h inside tests/wasmer_wasm.h. 2020-11-06 09:03:29 +01:00
Ivan Enderlin
f02b8510d8 chore(c-api) Assert that shared object directory is well constructed.
Before `pop`ing the filename, let's check whether it's what we expect!
2020-11-06 08:59:37 +01:00
Ivan Enderlin
ede0420920 test(c-api) Free some wasm_valtype_vec_t. 2020-11-05 16:30:39 +01:00
Ivan Enderlin
8ae283507e fix(c-api) Remove the TODO about memory leaks.
There is no memory leaks with those functions as far as I understand this code.

Check the following code as a fun playground, which reproduces a
typical use of `wasm_functype_params` or `_results` that both return a
`wasm_valtype_vec_t`:

```rust
struct wasm_valtype_t { x: u8 }

impl Drop for wasm_valtype_t {
    fn drop(&mut self) {
        println!("wasm_valtype_t {{ {} }} dropped!", self.x)
    }
}

struct wasm_valtype_vec_t {
    size: usize,
    data: *mut *mut wasm_valtype_t,
}

unsafe fn wasm_valtype_vec_delete(ptr: *mut wasm_valtype_vec_t) {
    let vec = &mut *ptr;

    if !vec.data.is_null() {
        let data: Vec<*mut wasm_valtype_t> = Vec::from_raw_parts(vec.data, vec.size, vec.size);
        let _data: Vec<Box<wasm_valtype_t>> = ::std::mem::transmute(data);
        vec.data = ::std::ptr::null_mut();
        vec.size = 0;
    }
}

fn main() {
    let x = Box::into_raw(Box::new(wasm_valtype_t { x: 1 }));
    let y = Box::into_raw(Box::new(wasm_valtype_t { x: 2 }));
    let z = Box::into_raw(Box::new(wasm_valtype_t { x: 3 }));
    let mut valtypes: Vec<*mut wasm_valtype_t> = vec![x, y, z];

    let vec = Box::into_raw(Box::new(wasm_valtype_vec_t {
        size: valtypes.len(),
        data: valtypes.as_mut_ptr(),
    }));
    ::std::mem::forget(valtypes);

    unsafe { wasm_valtype_vec_delete(vec as *mut _); }
}
```

It prints:

```
wasm_valtype_t { 1 } dropped!
wasm_valtype_t { 2 } dropped!
wasm_valtype_t { 3 } dropped!
```

All `wasm_valtype_t` are dropped correctly. Since they contain an
owned value, there is no leaks here.
2020-11-05 16:10:25 +01:00
Ivan Enderlin
83c8288c0f test(c-api) Add test case for wasm_module_imports. 2020-11-05 15:36:35 +01:00
Ivan Enderlin
00c003cab8 test(c-api) Use inline-c 0.1. 2020-11-05 14:47:46 +01:00