Skip to content

Commit

Permalink
Try #1028:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Dec 2, 2019
2 parents 19dfdec + 8df0591 commit 360a346
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#1028](https://github.com/wasmerio/wasmer/pull/1028) Fix `get_wasi_version` when a module has multiple import namespaces.
- [#1006](https://github.com/wasmerio/wasmer/pull/1006) Fix minor panic issue when `wasmer::compile_with` called with llvm backend
- [#1009](https://github.com/wasmerio/wasmer/pull/1009) Enable LLVM verifier for all tests, add new llvm-backend-tests crate.
- [#1004](https://github.com/wasmerio/wasmer/pull/1004) Add the Auto backend to enable to adapt backend usage depending on wasm file executed.
Expand Down
27 changes: 11 additions & 16 deletions lib/wasi/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,19 @@ pub enum WasiVersion {

/// Detect the version of WASI being used from the namespace
pub fn get_wasi_version(module: &Module) -> Option<WasiVersion> {
let mut import_iter = module
let namespace_table = &module.info().namespace_table;

module
.info()
.imported_functions
.iter()
.map(|(_, import_name)| import_name.namespace_index);
.find_map(|(_, import_name)| {
let namespace_index = import_name.namespace_index;

// returns None if empty
let first = import_iter.next()?;
if import_iter.all(|idx| idx == first) {
// once we know that all the namespaces are the same, we can use it to
// detect which version of WASI this is
match module.info().namespace_table.get(first) {
"wasi_unstable" => Some(WasiVersion::Snapshot0),
"wasi_snapshot_preview1" => Some(WasiVersion::Snapshot1),
_ => None,
}
} else {
// not all funcs have the same namespace, therefore it's not WASI
None
}
match namespace_table.get(namespace_index) {
"wasi_unstable" => Some(WasiVersion::Snapshot0),
"wasi_snapshot_preview1" => Some(WasiVersion::Snapshot1),
_ => None,
}
})
}

0 comments on commit 360a346

Please sign in to comment.