From ffff0441bc249528ffb42ab0865d86609c9965d1 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Oct 2020 15:05:26 +0200 Subject: [PATCH 1/3] 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. --- lib/c-api/src/wasm_c_api/externals/function.rs | 7 ++++++- lib/c-api/src/wasm_c_api/types/function.rs | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 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 b64f52d87bf..33d801ced8e 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -1,6 +1,6 @@ use super::super::store::wasm_store_t; use super::super::trap::wasm_trap_t; -use super::super::types::{wasm_functype_t, wasm_valkind_enum}; +use super::super::types::{wasm_functype_t, wasm_functype_t, wasm_valkind_enum}; use super::super::value::{wasm_val_inner, wasm_val_t}; use std::convert::TryInto; use std::ffi::c_void; @@ -154,3 +154,8 @@ pub unsafe extern "C" fn wasm_func_param_arity(func: &wasm_func_t) -> usize { pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize { func.inner.ty().results().len() } + +#[no_mangle] +pub extern "C" fn wasm_func_type(func: &wasm_func_t) -> Box { + Box::new(wasm_functype_t::new(func.inner.ty().clone())) +} diff --git a/lib/c-api/src/wasm_c_api/types/function.rs b/lib/c-api/src/wasm_c_api/types/function.rs index 7e95a39a2f0..69f63098614 100644 --- a/lib/c-api/src/wasm_c_api/types/function.rs +++ b/lib/c-api/src/wasm_c_api/types/function.rs @@ -17,6 +17,14 @@ impl wasm_functype_t { unreachable!("data corruption: `wasm_functype_t` does not contain a function") } } + + pub(crate) fn new(function_type: FunctionType) -> Self { + Self { + extern_: wasm_externtype_t { + inner: ExternType::Function(function_type), + }, + } + } } wasm_declare_vec!(functype); @@ -52,10 +60,9 @@ unsafe fn wasm_functype_new_inner( .map(Into::into) .collect::>(); - let extern_ = wasm_externtype_t { - inner: ExternType::Function(FunctionType::new(params, results)), - }; - Some(Box::new(wasm_functype_t { extern_ })) + Some(Box::new(wasm_functype_t::new(FunctionType::new( + params, results, + )))) } #[no_mangle] From 5149b2eaa83d65058036bbed35a2d07412bc7f05 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Oct 2020 15:09:44 +0200 Subject: [PATCH 2/3] doc(changelog) Add #1725. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1130551aa2d..ee82b9ecd35 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +- [#1725](https://github.com/wasmerio/wasmer/pull/1725) Implement `wasm_func_type` in the Wasm C API. - [#1715](https://github.com/wasmerio/wasmer/pull/1715) Register errors from `wasm_module_serialize` in the Wasm C API. - [#1709](https://github.com/wasmerio/wasmer/pull/1709) Implement `wasm_module_name` and `wasm_module_set_name` in the Wasm(er) C API. - [#1700](https://github.com/wasmerio/wasmer/pull/1700) Implement `wasm_externtype_copy` in the Wasm C API. From 2f692a1e2c32469d06cc0f5bc48b07b05709fc81 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 16 Oct 2020 09:42:12 +0200 Subject: [PATCH 3/3] fix(c-api) Fix merge issue. --- lib/c-api/src/wasm_c_api/externals/function.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 33d801ced8e..29e20adff40 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -1,6 +1,6 @@ use super::super::store::wasm_store_t; use super::super::trap::wasm_trap_t; -use super::super::types::{wasm_functype_t, wasm_functype_t, wasm_valkind_enum}; +use super::super::types::{wasm_functype_t, wasm_valkind_enum}; use super::super::value::{wasm_val_inner, wasm_val_t}; use std::convert::TryInto; use std::ffi::c_void;