Skip to content

Commit 1d319c0

Browse files
authored
c-api: refactor definitions with macroes (#4416)
Signed-off-by: spacewander <spacewanderlzx@gmail.com>
1 parent 6c70428 commit 1d319c0

File tree

5 files changed

+10
-54
lines changed

5 files changed

+10
-54
lines changed

crates/c-api/src/linker.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ pub struct wasmtime_linker_t {
1212
linker: Linker<crate::StoreData>,
1313
}
1414

15+
wasmtime_c_api_macros::declare_own!(wasmtime_linker_t);
16+
1517
#[no_mangle]
1618
pub extern "C" fn wasmtime_linker_new(engine: &wasm_engine_t) -> Box<wasmtime_linker_t> {
1719
Box::new(wasmtime_linker_t {
@@ -27,9 +29,6 @@ pub extern "C" fn wasmtime_linker_allow_shadowing(
2729
linker.linker.allow_shadowing(allow_shadowing);
2830
}
2931

30-
#[no_mangle]
31-
pub extern "C" fn wasmtime_linker_delete(_linker: Box<wasmtime_linker_t>) {}
32-
3332
macro_rules! to_str {
3433
($ptr:expr, $len:expr) => {
3534
match str::from_utf8(crate::slice_from_raw_parts($ptr, $len)) {

crates/c-api/src/module.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ pub struct wasmtime_module_t {
127127
pub(crate) module: Module,
128128
}
129129

130+
wasmtime_c_api_macros::declare_own!(wasmtime_module_t);
131+
130132
#[no_mangle]
131133
pub unsafe extern "C" fn wasmtime_module_new(
132134
engine: &wasm_engine_t,
@@ -142,9 +144,6 @@ pub unsafe extern "C" fn wasmtime_module_new(
142144
)
143145
}
144146

145-
#[no_mangle]
146-
pub extern "C" fn wasmtime_module_delete(_module: Box<wasmtime_module_t>) {}
147-
148147
#[no_mangle]
149148
pub extern "C" fn wasmtime_module_clone(module: &wasmtime_module_t) -> Box<wasmtime_module_t> {
150149
Box::new(module.clone())

crates/c-api/src/ref.rs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -195,49 +195,9 @@ pub extern "C" fn wasm_ref_as_trap_const(_ref: Option<&wasm_ref_t>) -> Option<&c
195195
#[repr(C)]
196196
pub struct wasm_foreign_t {}
197197

198+
wasmtime_c_api_macros::declare_ref!(wasm_foreign_t);
199+
198200
#[no_mangle]
199201
pub extern "C" fn wasm_foreign_new(_store: &crate::wasm_store_t) -> Box<wasm_foreign_t> {
200202
abort("wasm_foreign_new")
201203
}
202-
203-
#[no_mangle]
204-
pub extern "C" fn wasm_foreign_delete(_foreign: Box<wasm_foreign_t>) {}
205-
206-
#[no_mangle]
207-
pub extern "C" fn wasm_foreign_copy(r: &wasm_foreign_t) -> Box<wasm_foreign_t> {
208-
Box::new(r.clone())
209-
}
210-
211-
#[no_mangle]
212-
pub extern "C" fn wasm_foreign_same(_a: &wasm_foreign_t, _b: &wasm_foreign_t) -> bool {
213-
abort("wasm_foreign_same")
214-
}
215-
216-
#[no_mangle]
217-
pub extern "C" fn wasm_foreign_get_host_info(_foreign: &wasm_foreign_t) -> *mut c_void {
218-
std::ptr::null_mut()
219-
}
220-
221-
#[no_mangle]
222-
pub extern "C" fn wasm_foreign_set_host_info(_foreign: &wasm_foreign_t, _info: *mut c_void) {
223-
abort("wasm_foreign_set_host_info")
224-
}
225-
226-
#[no_mangle]
227-
pub extern "C" fn wasm_foreign_set_host_info_with_finalizer(
228-
_foreign: &wasm_foreign_t,
229-
_info: *mut c_void,
230-
_finalizer: Option<extern "C" fn(*mut c_void)>,
231-
) {
232-
abort("wasm_foreign_set_host_info_with_finalizer")
233-
}
234-
235-
#[no_mangle]
236-
pub extern "C" fn wasm_foreign_as_ref(_: &wasm_foreign_t) -> &wasm_ref_t {
237-
abort("wasm_foreign_as_ref")
238-
}
239-
240-
#[no_mangle]
241-
pub extern "C" fn wasm_foreign_as_ref_const(_: &wasm_foreign_t) -> Option<&wasm_ref_t> {
242-
abort("wasm_foreign_as_ref_const")
243-
}

crates/c-api/src/store.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub struct wasmtime_store_t {
6060
pub(crate) store: Store<StoreData>,
6161
}
6262

63+
wasmtime_c_api_macros::declare_own!(wasmtime_store_t);
64+
6365
pub type CStoreContext<'a> = StoreContext<'a, StoreData>;
6466
pub type CStoreContextMut<'a> = StoreContextMut<'a, StoreData>;
6567

@@ -77,9 +79,6 @@ pub struct StoreData {
7779
pub wasm_val_storage: Vec<Val>,
7880
}
7981

80-
#[no_mangle]
81-
pub extern "C" fn wasmtime_store_delete(_: Box<wasmtime_store_t>) {}
82-
8382
#[no_mangle]
8483
pub extern "C" fn wasmtime_store_new(
8584
engine: &wasm_engine_t,

crates/c-api/src/wasi.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ pub struct wasi_config_t {
4040
inherit_stderr: bool,
4141
}
4242

43+
wasmtime_c_api_macros::declare_own!(wasi_config_t);
44+
4345
impl wasi_config_t {
4446
pub fn into_wasi_ctx(self) -> Result<WasiCtx> {
4547
let mut builder = WasiCtxBuilder::new();
@@ -100,9 +102,6 @@ pub extern "C" fn wasi_config_new() -> Box<wasi_config_t> {
100102
Box::new(wasi_config_t::default())
101103
}
102104

103-
#[no_mangle]
104-
pub extern "C" fn wasi_config_delete(_config: Box<wasi_config_t>) {}
105-
106105
#[no_mangle]
107106
pub unsafe extern "C" fn wasi_config_set_argv(
108107
config: &mut wasi_config_t,

0 commit comments

Comments
 (0)