MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / wasm_instance_new

Function wasm_instance_new

crates/c-api/src/instance.rs:25–51  ·  view source on GitHub ↗
(
    store: &mut wasm_store_t,
    wasm_module: &wasm_module_t,
    imports: *const wasm_extern_vec_t,
    result: Option<&mut *mut wasm_trap_t>,
)

Source from the content-addressed store, hash-verified

23
24#[unsafe(no_mangle)]
25pub unsafe extern "C" fn wasm_instance_new(
26 store: &mut wasm_store_t,
27 wasm_module: &wasm_module_t,
28 imports: *const wasm_extern_vec_t,
29 result: Option<&mut *mut wasm_trap_t>,
30) -> Option<Box<wasm_instance_t>> {
31 let imports = (*imports)
32 .as_slice()
33 .iter()
34 .filter_map(|import| match import {
35 Some(i) => Some(i.which.clone()),
36 None => None,
37 })
38 .collect::<Vec<_>>();
39 match Instance::new(store.store.context_mut(), &wasm_module.module, &imports) {
40 Ok(instance) => Some(Box::new(wasm_instance_t::new(
41 store.store.clone(),
42 instance,
43 ))),
44 Err(e) => {
45 if let Some(ptr) = result {
46 *ptr = Box::into_raw(Box::new(wasm_trap_t::new(e)));
47 }
48 None
49 }
50 }
51}
52
53#[unsafe(no_mangle)]
54pub unsafe extern "C" fn wasm_instance_exports(

Callers 2

runFunction · 0.85
wasm.hFile · 0.85

Calls 5

context_mutMethod · 0.80
newFunction · 0.50
iterMethod · 0.45
as_sliceMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected