Remove the need for HostRef<Store> (#771)
* Remove the need for `HostRef<Store>` This commit goes through the public API of the `wasmtime` crate and removes the need for `HostRef<Store>`, as discussed in #708. This commit is accompanied with a few changes: * The `Store` type now also implements `Default`, creating a new `Engine` with default settings and returning that. * The `Store` type now implements `Clone`, and is documented as being a "cheap clone" aka being reference counted. As before there is no supported way to create a deep clone of a `Store`. * All APIs take/return `&Store` or `Store` instead of `HostRef<Store>`, and `HostRef<T>` is left as purely a detail of the C API. * The `global_exports` function is tagged as `#[doc(hidden)]` for now while we await its removal. * The `Store` type is not yet `Send` nor `Sync` due to the usage of `global_exports`, but it is intended to become so eventually. * Touch up comments on some examples * Run rustfmt
This commit is contained in:
@@ -141,7 +141,7 @@ impl RunCommand {
|
||||
}
|
||||
|
||||
let engine = Engine::new(&config);
|
||||
let store = HostRef::new(Store::new(&engine));
|
||||
let store = Store::new(&engine);
|
||||
let mut module_registry = HashMap::new();
|
||||
|
||||
// Make wasi available by default.
|
||||
@@ -151,7 +151,7 @@ impl RunCommand {
|
||||
let wasi_unstable = HostRef::new(if self.enable_wasi_c {
|
||||
#[cfg(feature = "wasi-c")]
|
||||
{
|
||||
let global_exports = store.borrow().global_exports().clone();
|
||||
let global_exports = store.global_exports().clone();
|
||||
let handle = instantiate_wasi_c(global_exports, &preopen_dirs, &argv, &self.vars)?;
|
||||
Instance::from_handle(&store, handle)
|
||||
}
|
||||
@@ -231,12 +231,12 @@ impl RunCommand {
|
||||
}
|
||||
|
||||
fn instantiate_module(
|
||||
store: &HostRef<Store>,
|
||||
store: &Store,
|
||||
module_registry: &HashMap<String, HostRef<Instance>>,
|
||||
path: &Path,
|
||||
) -> Result<(HostRef<Instance>, HostRef<Module>, Vec<u8>)> {
|
||||
// Read the wasm module binary either as `*.wat` or a raw binary
|
||||
let data = wat::parse_file(path.to_path_buf())?;
|
||||
let data = wat::parse_file(path)?;
|
||||
|
||||
let module = HostRef::new(Module::new(store, &data)?);
|
||||
|
||||
@@ -274,7 +274,7 @@ impl RunCommand {
|
||||
|
||||
fn handle_module(
|
||||
&self,
|
||||
store: &HostRef<Store>,
|
||||
store: &Store,
|
||||
module_registry: &HashMap<String, HostRef<Instance>>,
|
||||
) -> Result<()> {
|
||||
let (instance, module, data) =
|
||||
|
||||
Reference in New Issue
Block a user