Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/src/engine.rs
1692 views
1
use crate::wasm_config_t;
2
use wasmtime::Engine;
3
4
#[repr(C)]
5
#[derive(Clone)]
6
pub struct wasm_engine_t {
7
pub(crate) engine: Engine,
8
}
9
10
wasmtime_c_api_macros::declare_own!(wasm_engine_t);
11
12
#[unsafe(no_mangle)]
13
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
14
// Enable the `env_logger` crate since this is as good a place as any to
15
// support some "top level initialization" for the C API. Almost all support
16
// should go through this one way or another, so this ensures that
17
// `RUST_LOG` should work reasonably well.
18
//
19
// Note that we `drop` the result here since this fails after the first
20
// initialization attempt. We don't mind that though because this function
21
// can be called multiple times, so we just ignore the result.
22
#[cfg(feature = "logging")]
23
drop(env_logger::try_init());
24
25
Box::new(wasm_engine_t {
26
engine: Engine::default(),
27
})
28
}
29
30
#[unsafe(no_mangle)]
31
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
32
#[cfg(feature = "logging")]
33
drop(env_logger::try_init());
34
35
let config = c.config;
36
Box::new(wasm_engine_t {
37
engine: Engine::new(&config).unwrap(),
38
})
39
}
40
41
#[unsafe(no_mangle)]
42
pub extern "C" fn wasmtime_engine_clone(engine: &wasm_engine_t) -> Box<wasm_engine_t> {
43
Box::new(engine.clone())
44
}
45
46
#[unsafe(no_mangle)]
47
pub extern "C" fn wasmtime_engine_increment_epoch(engine: &wasm_engine_t) {
48
engine.engine.increment_epoch();
49
}
50
51
#[unsafe(no_mangle)]
52
pub extern "C" fn wasmtime_engine_is_pulley(engine: &wasm_engine_t) -> bool {
53
engine.engine.is_pulley()
54
}
55
56