Files
wasmtime/crates/c-api/src/engine.rs
Nick Fitzgerald a8ee0554a9 wasmtime: Initial, partial support for externref
This is enough to get an `externref -> externref` identity function
passing.

However, `externref`s that are dropped by compiled Wasm code are (safely)
leaked. Follow up work will leverage cranelift's stack maps to resolve this
issue.
2020-06-01 15:09:51 -07:00

36 lines
1.1 KiB
Rust

use crate::wasm_config_t;
use wasmtime::Engine;
#[repr(C)]
#[derive(Clone)]
pub struct wasm_engine_t {
pub(crate) engine: Engine,
}
wasmtime_c_api_macros::declare_own!(wasm_engine_t);
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
// Enable the `env_logger` crate since this is as good a place as any to
// support some "top level initialization" for the C API. Almost all support
// should go through this one way or another, so this ensures that
// `RUST_LOG` should work reasonably well.
//
// Note that we `drop` the result here since this fails after the first
// initialization attempt. We don't mind that though because this function
// can be called multiple times, so we just ignore the result.
drop(env_logger::try_init());
Box::new(wasm_engine_t {
engine: Engine::default(),
})
}
#[no_mangle]
pub extern "C" fn wasm_engine_new_with_config(c: Box<wasm_config_t>) -> Box<wasm_engine_t> {
let config = c.config;
Box::new(wasm_engine_t {
engine: Engine::new(&config),
})
}