diff --git a/CHANGELOG.md b/CHANGELOG.md index ff899fbee76..071700ce26b 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. 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..29e20adff40 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -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]