Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(c-api) Implement wasm_func_type #1725

Merged
merged 3 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion lib/c-api/src/wasm_c_api/externals/function.rs
Original file line number Diff line number Diff line change
@@ -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};
jubianchi marked this conversation as resolved.
Show resolved Hide resolved
use super::super::value::{wasm_val_inner, wasm_val_t};
use std::convert::TryInto;
use std::ffi::c_void;
Expand Down Expand Up @@ -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<wasm_functype_t> {
Box::new(wasm_functype_t::new(func.inner.ty().clone()))
}
15 changes: 11 additions & 4 deletions lib/c-api/src/wasm_c_api/types/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -52,10 +60,9 @@ unsafe fn wasm_functype_new_inner(
.map(Into::into)
.collect::<Vec<_>>();

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]
Expand Down