From 8d80befccdab8189a6711952eee012f418a6bef0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 22 Oct 2020 15:31:27 +0200 Subject: [PATCH 1/2] =?UTF-8?q?feat(c-api)=20Correctly=20implement=20?= =?UTF-8?q?=E2=80=9Ctrap=E2=80=9D=20in=20`wasm=5Ffunc=5Fnew*`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lib/c-api/src/wasm_c_api/externals/function.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs index 6f6319365b3..c7b2a3c666c 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -60,7 +60,8 @@ pub unsafe extern "C" fn wasm_func_new( if !trap.is_null() { let trap: Box = Box::from_raw(trap); - RuntimeError::raise(Box::new(trap.inner)); + + return Err(trap.inner); } let processed_results = results @@ -110,8 +111,13 @@ pub unsafe extern "C" fn wasm_func_new_with_env( ] .into(); - let _traps = callback(*env, &processed_args, &mut results); - // TODO: do something with `traps` + let trap = callback(*env, &processed_args, &mut results); + + if !trap.is_null() { + let trap: Box = Box::from_raw(trap); + + return Err(trap.inner); + } let processed_results = results .into_slice() From 184e3f4b2825663b77364710b613ff1176241be8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 22 Oct 2020 15:39:59 +0200 Subject: [PATCH 2/2] doc(changelog) Add #1751. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4621db71a3e..e236614ac02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#1710](https://github.com/wasmerio/wasmer/pull/1710) Memory for function call trampolines is now owned by the Artifact. ### Added +- [#1751](https://github.com/wasmerio/wasmer/pull/1751) Implement `wasm_trap_t` inside a function declared with `wasm_func_new_with_env` in the Wasm C API. - [#1741](https://github.com/wasmerio/wasmer/pull/1741) Implement `wasm_memory_type` in the Wasm C API. - [#1736](https://github.com/wasmerio/wasmer/pull/1736) Implement `wasm_global_type` in the Wasm C API. - [#1699](https://github.com/wasmerio/wasmer/pull/1699) Update `wasm.h` to its latest version.