Remove the need for HostRef<Module> (#778)

* Remove the need for `HostRef<Module>`

This commit continues previous work and also #708 by removing the need
to use `HostRef<Module>` in the API of the `wasmtime` crate. The API
changes performed here are:

* The `Module` type is now itself internally reference counted.
* The `Module::store` function now returns the `Store` that was used to
  create a `Module`
* Documentation for `Module` and its methods have been expanded.

* Fix compliation of test programs harness

* Fix the python extension

* Update `CodeMemory` to be `Send + Sync`

This commit updates the `CodeMemory` type in wasmtime to be both `Send`
and `Sync` by updating the implementation of `Mmap` to not store raw
pointers. This avoids the need for an `unsafe impl` and leaves the
unsafety as it is currently.

* Fix a typo
This commit is contained in:
Alex Crichton
2020-01-08 14:42:37 -06:00
committed by GitHub
parent c975a92a3a
commit 7b33f1c619
22 changed files with 221 additions and 130 deletions

View File

@@ -44,19 +44,15 @@ pub fn instantiate(wasm: &[u8], strategy: Strategy) {
let engine = Engine::new(&config);
let store = Store::new(&engine);
let module =
HostRef::new(Module::new(&store, wasm).expect("Failed to compile a valid Wasm module!"));
let module = Module::new(&store, wasm).expect("Failed to compile a valid Wasm module!");
let imports = {
let module = module.borrow();
match dummy_imports(&store, module.imports()) {
Ok(imps) => imps,
Err(_) => {
// There are some value types that we can't synthesize a
// dummy value for (e.g. anyrefs) and for modules that
// import things of these types we skip instantiation.
return;
}
let imports = match dummy_imports(&store, module.imports()) {
Ok(imps) => imps,
Err(_) => {
// There are some value types that we can't synthesize a
// dummy value for (e.g. anyrefs) and for modules that
// import things of these types we skip instantiation.
return;
}
};
@@ -92,7 +88,7 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
let mut config: Option<Config> = None;
let mut engine: Option<Engine> = None;
let mut store: Option<Store> = None;
let mut modules: HashMap<usize, HostRef<Module>> = Default::default();
let mut modules: HashMap<usize, Module> = Default::default();
let mut instances: HashMap<usize, HostRef<Instance>> = Default::default();
for call in api.calls {
@@ -117,10 +113,10 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
}
ApiCall::ModuleNew { id, wasm } => {
let module = HostRef::new(match Module::new(store.as_ref().unwrap(), &wasm.wasm) {
let module = match Module::new(store.as_ref().unwrap(), &wasm.wasm) {
Ok(m) => m,
Err(_) => continue,
});
};
let old = modules.insert(id, module);
assert!(old.is_none());
}
@@ -135,16 +131,13 @@ pub fn make_api_calls(api: crate::generators::api::ApiCalls) {
None => continue,
};
let imports = {
let module = module.borrow();
match dummy_imports(store.as_ref().unwrap(), module.imports()) {
Ok(imps) => imps,
Err(_) => {
// There are some value types that we can't synthesize a
// dummy value for (e.g. anyrefs) and for modules that
// import things of these types we skip instantiation.
continue;
}
let imports = match dummy_imports(store.as_ref().unwrap(), module.imports()) {
Ok(imps) => imps,
Err(_) => {
// There are some value types that we can't synthesize a
// dummy value for (e.g. anyrefs) and for modules that
// import things of these types we skip instantiation.
continue;
}
};