diff --git a/crates/c-api/src/lib.rs b/crates/c-api/src/lib.rs index 24490384ad..82c1f819d7 100644 --- a/crates/c-api/src/lib.rs +++ b/crates/c-api/src/lib.rs @@ -257,6 +257,7 @@ pub struct wasm_importtype_t { ty: ImportType, module_cache: Option, name_cache: Option, + type_cache: Option, } declare_vec!(wasm_importtype_vec_t, *mut wasm_importtype_t); @@ -835,6 +836,7 @@ pub unsafe extern "C" fn wasm_module_new( ty: i.clone(), module_cache: None, name_cache: None, + type_cache: None, }) .collect::>(); let exports = module @@ -1073,11 +1075,14 @@ pub unsafe extern "C" fn wasm_importtype_name(it: *const wasm_importtype_t) -> * pub unsafe extern "C" fn wasm_importtype_type( it: *const wasm_importtype_t, ) -> *const wasm_externtype_t { - let ty = Box::new(wasm_externtype_t { - ty: (*it).ty.ty().clone(), - cache: wasm_externtype_t_type_cache::Empty, - }); - Box::into_raw(ty) + if (*it).type_cache.is_none() { + let it = (it as *mut wasm_importtype_t).as_mut().unwrap(); + it.type_cache = Some(wasm_externtype_t { + ty: (*it).ty.ty().clone(), + cache: wasm_externtype_t_type_cache::Empty, + }); + } + (*it).type_cache.as_ref().unwrap() } #[no_mangle] @@ -1230,6 +1235,16 @@ pub unsafe extern "C" fn wasm_externtype_kind(et: *const wasm_externtype_t) -> w } } +#[no_mangle] +pub unsafe extern "C" fn wasm_func_type(f: *const wasm_func_t) -> *mut wasm_functype_t { + let ft = Box::new(wasm_functype_t { + functype: (*f).func().borrow().ty().clone(), + params_cache: None, + returns_cache: None, + }); + Box::into_raw(ft) +} + #[no_mangle] pub unsafe extern "C" fn wasm_func_param_arity(f: *const wasm_func_t) -> usize { (*f).func().borrow().param_arity()