c-api: Add a way to get type of wasmtime_module_t (#3959)

My previous PR at #3958 accidentally removed the only way to get type
information from a `wasmtime_module_t`, so this commit re-adds methods
back in to continue to be able to get import/export information from a
compiled module.
This commit is contained in:
Alex Crichton
2022-03-24 13:32:56 -05:00
committed by GitHub
parent 76b82910c9
commit 13ec5ff64c
2 changed files with 44 additions and 6 deletions

View File

@@ -47,10 +47,8 @@ pub unsafe extern "C" fn wasm_module_validate(
Module::validate(store.store.context().engine(), binary.as_slice()).is_ok()
}
#[no_mangle]
pub extern "C" fn wasm_module_exports(module: &wasm_module_t, out: &mut wasm_exporttype_vec_t) {
fn fill_exports(module: &Module, out: &mut wasm_exporttype_vec_t) {
let exports = module
.module
.exports()
.map(|e| {
Some(Box::new(wasm_exporttype_t::new(
@@ -62,10 +60,8 @@ pub extern "C" fn wasm_module_exports(module: &wasm_module_t, out: &mut wasm_exp
out.set_buffer(exports);
}
#[no_mangle]
pub extern "C" fn wasm_module_imports(module: &wasm_module_t, out: &mut wasm_importtype_vec_t) {
fn fill_imports(module: &Module, out: &mut wasm_importtype_vec_t) {
let imports = module
.module
.imports()
.map(|i| {
Some(Box::new(wasm_importtype_t::new(
@@ -78,6 +74,16 @@ pub extern "C" fn wasm_module_imports(module: &wasm_module_t, out: &mut wasm_imp
out.set_buffer(imports);
}
#[no_mangle]
pub extern "C" fn wasm_module_exports(module: &wasm_module_t, out: &mut wasm_exporttype_vec_t) {
fill_exports(&module.module, out);
}
#[no_mangle]
pub extern "C" fn wasm_module_imports(module: &wasm_module_t, out: &mut wasm_importtype_vec_t) {
fill_imports(&module.module, out);
}
#[no_mangle]
pub extern "C" fn wasm_module_share(module: &wasm_module_t) -> Box<wasm_shared_module_t> {
Box::new(wasm_shared_module_t {
@@ -144,6 +150,22 @@ pub extern "C" fn wasmtime_module_clone(module: &wasmtime_module_t) -> Box<wasmt
Box::new(module.clone())
}
#[no_mangle]
pub extern "C" fn wasmtime_module_exports(
module: &wasmtime_module_t,
out: &mut wasm_exporttype_vec_t,
) {
fill_exports(&module.module, out);
}
#[no_mangle]
pub extern "C" fn wasmtime_module_imports(
module: &wasmtime_module_t,
out: &mut wasm_importtype_vec_t,
) {
fill_imports(&module.module, out);
}
#[no_mangle]
pub unsafe extern "C" fn wasmtime_module_validate(
engine: &wasm_engine_t,