wasmer_c_api/wasm_c_api/
store.rs1use super::engine::wasm_engine_t;
2use std::cell::UnsafeCell;
3use std::rc::Rc;
4use wasmer_api::{AsStoreMut, AsStoreRef, Store, StoreMut, StoreRef as BaseStoreRef};
5
6#[derive(Clone)]
7pub struct StoreRef {
8 inner: Rc<UnsafeCell<Store>>,
9}
10
11impl StoreRef {
12 pub unsafe fn store(&self) -> BaseStoreRef<'_> {
13 unsafe { (*self.inner.get()).as_store_ref() }
14 }
15
16 pub unsafe fn store_mut(&mut self) -> StoreMut<'_> {
17 unsafe { (*self.inner.get()).as_store_mut() }
18 }
19}
20
21#[allow(non_camel_case_types)]
23pub struct wasm_store_t {
24 pub(crate) inner: StoreRef,
25}
26
27#[unsafe(no_mangle)]
33pub unsafe extern "C" fn wasm_store_new(
34 engine: Option<&wasm_engine_t>,
35) -> Option<Box<wasm_store_t>> {
36 let engine = engine?;
37 let store = Store::new(engine.inner.clone());
38
39 Some(Box::new(wasm_store_t {
40 inner: StoreRef {
41 inner: Rc::new(UnsafeCell::new(store)),
42 },
43 }))
44}
45
46#[unsafe(no_mangle)]
52pub unsafe extern "C" fn wasm_store_delete(_store: Option<Box<wasm_store_t>>) {}