c-api: refactor definitions with macroes (#4416)
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
This commit is contained in:
@@ -12,6 +12,8 @@ pub struct wasmtime_linker_t {
|
||||
linker: Linker<crate::StoreData>,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_own!(wasmtime_linker_t);
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_linker_new(engine: &wasm_engine_t) -> Box<wasmtime_linker_t> {
|
||||
Box::new(wasmtime_linker_t {
|
||||
@@ -27,9 +29,6 @@ pub extern "C" fn wasmtime_linker_allow_shadowing(
|
||||
linker.linker.allow_shadowing(allow_shadowing);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_linker_delete(_linker: Box<wasmtime_linker_t>) {}
|
||||
|
||||
macro_rules! to_str {
|
||||
($ptr:expr, $len:expr) => {
|
||||
match str::from_utf8(crate::slice_from_raw_parts($ptr, $len)) {
|
||||
|
||||
@@ -127,6 +127,8 @@ pub struct wasmtime_module_t {
|
||||
pub(crate) module: Module,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_own!(wasmtime_module_t);
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasmtime_module_new(
|
||||
engine: &wasm_engine_t,
|
||||
@@ -142,9 +144,6 @@ pub unsafe extern "C" fn wasmtime_module_new(
|
||||
)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_module_delete(_module: Box<wasmtime_module_t>) {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_module_clone(module: &wasmtime_module_t) -> Box<wasmtime_module_t> {
|
||||
Box::new(module.clone())
|
||||
|
||||
@@ -195,49 +195,9 @@ pub extern "C" fn wasm_ref_as_trap_const(_ref: Option<&wasm_ref_t>) -> Option<&c
|
||||
#[repr(C)]
|
||||
pub struct wasm_foreign_t {}
|
||||
|
||||
wasmtime_c_api_macros::declare_ref!(wasm_foreign_t);
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_new(_store: &crate::wasm_store_t) -> Box<wasm_foreign_t> {
|
||||
abort("wasm_foreign_new")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_delete(_foreign: Box<wasm_foreign_t>) {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_copy(r: &wasm_foreign_t) -> Box<wasm_foreign_t> {
|
||||
Box::new(r.clone())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_same(_a: &wasm_foreign_t, _b: &wasm_foreign_t) -> bool {
|
||||
abort("wasm_foreign_same")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_get_host_info(_foreign: &wasm_foreign_t) -> *mut c_void {
|
||||
std::ptr::null_mut()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_set_host_info(_foreign: &wasm_foreign_t, _info: *mut c_void) {
|
||||
abort("wasm_foreign_set_host_info")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_set_host_info_with_finalizer(
|
||||
_foreign: &wasm_foreign_t,
|
||||
_info: *mut c_void,
|
||||
_finalizer: Option<extern "C" fn(*mut c_void)>,
|
||||
) {
|
||||
abort("wasm_foreign_set_host_info_with_finalizer")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_as_ref(_: &wasm_foreign_t) -> &wasm_ref_t {
|
||||
abort("wasm_foreign_as_ref")
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_foreign_as_ref_const(_: &wasm_foreign_t) -> Option<&wasm_ref_t> {
|
||||
abort("wasm_foreign_as_ref_const")
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ pub struct wasmtime_store_t {
|
||||
pub(crate) store: Store<StoreData>,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_own!(wasmtime_store_t);
|
||||
|
||||
pub type CStoreContext<'a> = StoreContext<'a, StoreData>;
|
||||
pub type CStoreContextMut<'a> = StoreContextMut<'a, StoreData>;
|
||||
|
||||
@@ -77,9 +79,6 @@ pub struct StoreData {
|
||||
pub wasm_val_storage: Vec<Val>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_store_delete(_: Box<wasmtime_store_t>) {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasmtime_store_new(
|
||||
engine: &wasm_engine_t,
|
||||
|
||||
@@ -40,6 +40,8 @@ pub struct wasi_config_t {
|
||||
inherit_stderr: bool,
|
||||
}
|
||||
|
||||
wasmtime_c_api_macros::declare_own!(wasi_config_t);
|
||||
|
||||
impl wasi_config_t {
|
||||
pub fn into_wasi_ctx(self) -> Result<WasiCtx> {
|
||||
let mut builder = WasiCtxBuilder::new();
|
||||
@@ -100,9 +102,6 @@ pub extern "C" fn wasi_config_new() -> Box<wasi_config_t> {
|
||||
Box::new(wasi_config_t::default())
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasi_config_delete(_config: Box<wasi_config_t>) {}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasi_config_set_argv(
|
||||
config: &mut wasi_config_t,
|
||||
|
||||
Reference in New Issue
Block a user