Commit Graph

288 Commits

Author SHA1 Message Date
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
Ivan Enderlin
9059a07ef8 test(c-api) Add test cases for wasm_module_(de)serialize. 2020-11-03 15:33:31 +01:00
Ivan Enderlin
4f0454c114 test(c-api) Fix C warnings. 2020-11-03 14:06:21 +01:00
Ivan Enderlin
a4493ed990 doc(tests) Improve documentation of tests/wasmer_wasm.h. 2020-11-03 10:43:40 +01:00
Ivan Enderlin
1d208af530 test(c-api) Create a tests/wasmer_wasm.h file.
Remove the `build.rs` hack to add helper functions that are used only
in our tests. Now the tests can use the `tests/wasmer_wasm.h` file,
which simplifies the test workflow: No need to hack the build script
or anything if we want to add a helper function.
2020-11-03 10:41:00 +01:00
Ivan Enderlin
059dfceb60 chore(c-api) Update the header files. 2020-11-02 17:46:36 +01:00
Ivan Enderlin
d9641dba5d test(c-api) Test wasm_module_validate, _new, _delete and _exports. 2020-11-02 17:44:57 +01:00
Ivan Enderlin
b93f3f5a9f test(c-api) Add more test case for wat2wasm. 2020-11-02 17:44:50 +01:00
Ivan Enderlin
348f164446 feat(c-api) Use the “limits sentinel” for table max limit. 2020-11-02 17:39:37 +01:00
Ivan Enderlin
ffba18d7b5 feat(c-api) Add a wasm_byte_vec_new_from_string helper.
It's very similar to `wasm_name_new_from_string` but for
`wasm_byte_vec_t`. It does not make sense to get that in the standard,
but it's very useful when writing tests.
2020-11-02 16:23:56 +01:00
Ivan Enderlin
6b75648d82 test(c-api) Configure and start using inline-c-rs. 2020-11-02 15:49:52 +01:00
bors[bot]
591691bc17 Merge #1765
1765: doc(c-api) Update documentation. r=Hywan a=Hywan

# Description

This patch adds documentation to the  `engine.rs` module.

# Review

- [ ] ~Add a short description of the the change to the CHANGELOG.md file~ not necessary


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-30 10:05:52 +00:00
Ivan Enderlin
bdb0dc772d Merge branch 'master' into feat-c-api-instance-new-traps 2020-10-30 09:38:06 +01:00
Ivan Enderlin
9583a91678 fix(c-api) wasm_trap_t** in wasm_instance_new does not represent an array.
The `wasm_trap_t**` argument of `wasm_instance_new` represents an
output pointer to a `wasm_trap_t*`, not an array of
`wasm_trap_t*`. This patch updates the code accordingly.
2020-10-30 09:37:05 +01:00
Syrus
2387ec07b6 Upgrade dependencies 2020-10-29 22:59:48 -07:00
Mark McCaskey
adc40aeae3 Merge branch 'master' into feature/add-table-example 2020-10-27 11:57:08 -07:00
Ivan Enderlin
766ab8c0c1 Merge branch 'master' into pr/1604 2020-10-27 14:55:02 +01:00
Ivan Enderlin
ce525e7e90 doc(c-api) Update documentation. 2020-10-27 13:53:47 +01:00
Ivan Enderlin
4102dcb9ac feat(c-api) Shrink vector of traps.
Ensure that the size of the vector of the instance's traps equals its
capacity by shrinking it.
2020-10-27 11:49:01 +01:00
Ivan Enderlin
452181326a fix(c-api) Remove a debug_assert macro. 2020-10-27 11:44:38 +01:00
jubianchi
2452b9a604 chore(doc): Add the Wasmer logo to the generated API documentation 2020-10-26 22:37:30 +01:00
Nick Lewycky
126819eda6 Don't assume the serialized data came from engine-jit. 2020-10-26 12:32:08 -07:00
Ivan Enderlin
38c57e138f test(c-api) Enable the wasm-c-api-start test. 2020-10-26 15:27:20 +01:00
Ivan Enderlin
a2d96d9ba7 feat(c-api) Implement the traps argument of wasm_instance_new.
When running `Instance::new`, it can error with an
`InstantiationError`. There is 2 scenarii:

1. Either it's a `InstantiationError::Link`. In this case, the
   `wasm_instance_new` function must return `NULL` and register the
   error in the Wasmer error registry.

2. Either it's a `InstantiationError::Start`. In this case, the
   `wasm_instance_new` function must return `NULL` and the error must be
   converted into a `wasm_trap_t`, which is stored in the `wasm_trap_t**`
   array. This array is initialized by `wasm_instance_new` itself.
2020-10-26 15:27:20 +01:00
bors[bot]
c6978ea967 Merge #1751
1751: feat(c-api) Correctly implement “trap” in `wasm_func_new*` r=Hywan a=Hywan

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.

Fixes https://github.com/wasmerio/wasmer/issues/1744.

Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-26 13:52:18 +00:00
Nick Lewycky
1b3254cf6a Move the generated-by comment up to the first comment. 2020-10-23 11:16:30 -07:00
Nick Lewycky
8ab49df7ab Ahem. 2020-10-23 11:15:31 -07:00
Nick Lewycky
9085480ad0 Update the generated file too, of course. 2020-10-23 11:14:06 -07:00
Nick Lewycky
e28fd7e755 Add a comment indicating what generates this file. 2020-10-23 11:10:21 -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
729a044c75 Add misc updates from feedback 2020-10-21 16:34:27 -07:00
Ivan Enderlin
7214b98165 feat(c-api) Implement wasm_memory_type. 2020-10-20 15:49:34 +02:00
Mark McCaskey
6d326233f7 Merge branch 'master' into fix/create-exe-genearted-code-bugs 2020-10-19 10:03:05 -07:00
jubianchi
5c26a81598 feat(c-api): Implement wasm_global_type
This patch adds a `wasm_globaltype_t::new` constructor for use by the
new `wasm_global_type` function and the existing
`wasm_globaltype_new_inner` function.

Note: `wasm_global_type` is defined here:
193d7c8ce1/lib/c-api/tests/wasm_c_api/wasm-c-api/include/wasm.h (L436)
2020-10-19 16:02:21 +02:00
Ivan Enderlin
460d034379 chore(c-api) Remove outdated comment. 2020-10-19 09:23:08 +02:00
Ivan Enderlin
afa5ab5e52 Merge branch 'master' into fix-c-api-trampoline 2020-10-19 09:22:13 +02:00
Ivan Enderlin
a73e457976 Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-19 08:01:00 +02:00
Syrus
bb1b89f4f7 Removed all usages of wasm_instance_get_vmctx_ptr 2020-10-16 21:39:23 -07:00
Mark McCaskey
1ee99d394c Address feedback and fix small issue with cfg logic 2020-10-16 17:38:59 -07:00
bors[bot]
1d4bf9b7fa Merge #1725
1725: feat(c-api) Implement `wasm_func_type` r=MarkMcCaskey a=Hywan

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.

Note: `wasm_func_type` is defined in 193d7c8ce1/lib/c-api/tests/wasm_c_api/wasm-c-api/include/wasm.h (L421).

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Ivan Enderlin <ivan@mnt.io>
2020-10-16 23:59:42 +00:00
Ivan Enderlin
d7d40e542f Merge branch 'master' into feat-c-api-update-wasm-h 2020-10-16 10:18:46 +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