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:
@@ -59,6 +59,22 @@ WASM_API_EXTERN void wasmtime_module_delete(wasmtime_module_t *m);
|
|||||||
*/
|
*/
|
||||||
WASM_API_EXTERN wasmtime_module_t *wasmtime_module_clone(wasmtime_module_t *m);
|
WASM_API_EXTERN wasmtime_module_t *wasmtime_module_clone(wasmtime_module_t *m);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Same as #wasm_module_imports, but for #wasmtime_module_t.
|
||||||
|
*/
|
||||||
|
WASM_API_EXTERN void wasmtime_module_imports(
|
||||||
|
const wasmtime_module_t *module,
|
||||||
|
wasm_importtype_vec_t *out
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Same as #wasm_module_exports, but for #wasmtime_module_t.
|
||||||
|
*/
|
||||||
|
WASM_API_EXTERN void wasmtime_module_exports(
|
||||||
|
const wasmtime_module_t *module,
|
||||||
|
wasm_exporttype_vec_t *out
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Validate a WebAssembly binary.
|
* \brief Validate a WebAssembly binary.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -47,10 +47,8 @@ pub unsafe extern "C" fn wasm_module_validate(
|
|||||||
Module::validate(store.store.context().engine(), binary.as_slice()).is_ok()
|
Module::validate(store.store.context().engine(), binary.as_slice()).is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
fn fill_exports(module: &Module, out: &mut wasm_exporttype_vec_t) {
|
||||||
pub extern "C" fn wasm_module_exports(module: &wasm_module_t, out: &mut wasm_exporttype_vec_t) {
|
|
||||||
let exports = module
|
let exports = module
|
||||||
.module
|
|
||||||
.exports()
|
.exports()
|
||||||
.map(|e| {
|
.map(|e| {
|
||||||
Some(Box::new(wasm_exporttype_t::new(
|
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);
|
out.set_buffer(exports);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
fn fill_imports(module: &Module, out: &mut wasm_importtype_vec_t) {
|
||||||
pub extern "C" fn wasm_module_imports(module: &wasm_module_t, out: &mut wasm_importtype_vec_t) {
|
|
||||||
let imports = module
|
let imports = module
|
||||||
.module
|
|
||||||
.imports()
|
.imports()
|
||||||
.map(|i| {
|
.map(|i| {
|
||||||
Some(Box::new(wasm_importtype_t::new(
|
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);
|
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]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_module_share(module: &wasm_module_t) -> Box<wasm_shared_module_t> {
|
pub extern "C" fn wasm_module_share(module: &wasm_module_t) -> Box<wasm_shared_module_t> {
|
||||||
Box::new(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())
|
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]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasmtime_module_validate(
|
pub unsafe extern "C" fn wasmtime_module_validate(
|
||||||
engine: &wasm_engine_t,
|
engine: &wasm_engine_t,
|
||||||
|
|||||||
Reference in New Issue
Block a user