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:
@@ -126,7 +126,7 @@ impl wasmtime::Callable for WrappedFn {
|
||||
}
|
||||
|
||||
pub fn wrap_into_pyfunction(
|
||||
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||
store: &wasmtime::Store,
|
||||
callable: &PyAny,
|
||||
) -> PyResult<wasmtime::HostRef<wasmtime::Func>> {
|
||||
if !callable.hasattr("__annotations__")? {
|
||||
|
||||
@@ -44,11 +44,7 @@ impl InstantiateResultObject {
|
||||
}
|
||||
}
|
||||
|
||||
fn find_export_in(
|
||||
obj: &PyAny,
|
||||
store: &wasmtime::HostRef<wasmtime::Store>,
|
||||
name: &str,
|
||||
) -> PyResult<wasmtime::Extern> {
|
||||
fn find_export_in(obj: &PyAny, store: &wasmtime::Store, name: &str) -> PyResult<wasmtime::Extern> {
|
||||
let obj = obj.cast_as::<PyDict>()?;
|
||||
|
||||
Ok(if let Some(item) = obj.get_item(name) {
|
||||
@@ -86,7 +82,7 @@ pub fn instantiate(
|
||||
let wasm_data = buffer_source.as_bytes();
|
||||
|
||||
let engine = wasmtime::Engine::new(&wasmtime::Config::new().wasm_multi_value(true));
|
||||
let store = wasmtime::HostRef::new(wasmtime::Store::new(&engine));
|
||||
let store = wasmtime::Store::new(&engine);
|
||||
|
||||
let module = wasmtime::HostRef::new(wasmtime::Module::new(&store, wasm_data).map_err(err2py)?);
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ fn generate_load(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
||||
use #root::anyhow::{bail, format_err};
|
||||
|
||||
let engine = Engine::new(Config::new().wasm_multi_value(true));
|
||||
let store = HostRef::new(Store::new(&engine));
|
||||
let global_exports = store.borrow().global_exports().clone();
|
||||
let store = Store::new(&engine);
|
||||
let global_exports = store.global_exports().clone();
|
||||
|
||||
let data = #root::wasmtime_interface_types::ModuleData::new(&bytes)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user