Skip to content

Commit

Permalink
Merge pull request #834 from pventuzelo/ventuzelo/fix-830-panic-unwra…
Browse files Browse the repository at this point in the history
…p-wasmer-args

Fix 830 panic unwrap wasmer args
  • Loading branch information
syrusakbary authored Sep 25, 2019
2 parents 8a92e52 + de533af commit c52c44a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments.

## **[Unreleased]**

- [#834](https://github.com/wasmerio/wasmer/pull/834) Fix panic when unwraping `wasmer` arguments
- [#833](https://github.com/wasmerio/wasmer/pull/833) Add doc example of using ImportObject's new `maybe_with_namespace` method
- [#832](https://github.com/wasmerio/wasmer/pull/832) Delete unused runtime ABI
- [#809](https://github.com/wasmerio/wasmer/pull/809) Fix bugs leading to panics in `LocalBacking`.
Expand Down
37 changes: 21 additions & 16 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate loader module: {:?}", e))?;

let args: Vec<Value> = options
.args
.iter()
.map(|arg| arg.as_str())
.map(|x| {
Value::I32(x.parse().expect(&format!(
let mut args: Vec<Value> = Vec::new();
for arg in options.args.iter() {
let x = arg.as_str().parse().map_err(|_| {
format!(
"Can't parse the provided argument {:?} as a integer",
x
)))
})
.collect();
arg.as_str()
)
})?;
args.push(Value::I32(x));
}

let index = instance
.resolve_func("_start")
.expect("The loader requires a _start function to be present in the module");
Expand Down Expand Up @@ -658,12 +658,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?;

let args: Vec<Value> = options
.args
.iter()
.map(|arg| arg.as_str())
.map(|x| Value::I32(x.parse().unwrap()))
.collect();
let mut args: Vec<Value> = Vec::new();
for arg in options.args.iter() {
let x = arg.as_str().parse().map_err(|_| {
format!(
"Can't parse the provided argument {:?} as a integer",
arg.as_str()
)
})?;
args.push(Value::I32(x));
}

instance
.dyn_func("main")
.map_err(|e| format!("{:?}", e))?
Expand Down

0 comments on commit c52c44a

Please sign in to comment.