From e688b374a665aa0d3350a6757e7ce4ae0a27855c Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 10:24:44 -0800 Subject: [PATCH 1/6] fix some typos (#136) --- lib/runtime-core/src/instance.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/runtime-core/src/instance.rs b/lib/runtime-core/src/instance.rs index 49fad4752..2a2ce9cb5 100644 --- a/lib/runtime-core/src/instance.rs +++ b/lib/runtime-core/src/instance.rs @@ -168,7 +168,7 @@ impl Instance { self.call_with_index(func_index, args) } - /// Returns a immutable reference to the + /// Returns an immutable reference to the /// [`Ctx`] used by this Instance. /// /// [`Ctx`]: struct.Ctx.html @@ -184,7 +184,7 @@ impl Instance { unsafe { &mut *self.inner.vmctx } } - /// Returns a iterator over all of the items + /// Returns an iterator over all of the items /// exported from this instance. pub fn exports(&mut self) -> ExportIter { ExportIter::new(&self.module, &mut self.inner) From d82155f558cd77d2f564d793f6bb27e845b68b5d Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 14:26:48 -0800 Subject: [PATCH 2/6] pass reference to imports object when instantiating --- src/bin/wasmer.rs | 2 +- src/webassembly.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 28aea2d1e..4ebfb76d3 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -85,7 +85,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> { }; let mut instance = module - .instantiate(import_object) + .instantiate(&import_object) .map_err(|e| format!("Can't instantiate module: {:?}", e))?; webassembly::run_instance( diff --git a/src/webassembly.rs b/src/webassembly.rs index 2dc8141ff..bbe50b4d6 100644 --- a/src/webassembly.rs +++ b/src/webassembly.rs @@ -41,7 +41,7 @@ pub fn instantiate(buffer_source: &[u8], import_object: ImportObject) -> Result< let module = compile(&buffer_source[..])?; debug!("webassembly - instantiating"); - let instance = module.instantiate(import_object)?; + let instance = module.instantiate(&import_object)?; debug!("webassembly - instance created"); Ok(ResultObject { From c771f2e6771c9c1c0d6d78c157c1ec841567cb44 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 15:00:57 -0800 Subject: [PATCH 3/6] fix more cases of passing imports by reference to instantiate --- lib/spectests/examples/simple/main.rs | 4 ++-- lib/spectests/examples/test.rs | 4 ++-- lib/spectests/tests/semantics.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index 00dcf1890..349c19d57 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -45,14 +45,14 @@ fn main() -> Result<()> { }, }; - let inner_instance = inner_module.instantiate(import_object)?; + let inner_instance = inner_module.instantiate(&import_object)?; let outer_imports = imports! { "env" => inner_instance, }; let outer_module = wasmer_runtime_core::compile_with(EXAMPLE_WASM, &CraneliftCompiler::new())?; - let outer_instance = outer_module.instantiate(outer_imports)?; + let outer_instance = outer_module.instantiate(&outer_imports)?; let ret = outer_instance.call("main", &[Value::I32(42)])?; println!("ret: {:?}", ret); diff --git a/lib/spectests/examples/test.rs b/lib/spectests/examples/test.rs index 6a81b8e21..6f725e994 100644 --- a/lib/spectests/examples/test.rs +++ b/lib/spectests/examples/test.rs @@ -27,7 +27,7 @@ fn create_module_1() -> Instance { let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new()) .expect("WASM can't be compiled"); module - .instantiate(generate_imports()) + .instantiate(&generate_imports()) .expect("WASM can't be instantiated") } @@ -47,7 +47,7 @@ pub fn generate_imports() -> ImportObject { let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new()) .expect("WASM can't be compiled"); let instance = module - .instantiate(ImportObject::new()) + .instantiate(&ImportObject::new()) .expect("WASM can't be instantiated"); let mut imports = ImportObject::new(); imports.register("spectest", instance); diff --git a/lib/spectests/tests/semantics.rs b/lib/spectests/tests/semantics.rs index b224b87bf..d447b385f 100644 --- a/lib/spectests/tests/semantics.rs +++ b/lib/spectests/tests/semantics.rs @@ -25,7 +25,7 @@ mod tests { let module = wasmer_runtime_core::compile_with(&wasm_binary[..], &CraneliftCompiler::new()) .expect("WASM can't be compiled"); let instance = module - .instantiate(ImportObject::new()) + .instantiate(&ImportObject::new()) .expect("WASM can't be instantiated"); let result = instance.call("stack-overflow", &[]); From 73a8619bc59366a58cc2fb5570a49aa7bca76c88 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 15:01:12 -0800 Subject: [PATCH 4/6] do not need to dereference an enum --- lib/spectests/tests/semantics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spectests/tests/semantics.rs b/lib/spectests/tests/semantics.rs index d447b385f..c364dca29 100644 --- a/lib/spectests/tests/semantics.rs +++ b/lib/spectests/tests/semantics.rs @@ -30,7 +30,7 @@ mod tests { let result = instance.call("stack-overflow", &[]); match result { - Err(err) => match *err { + Err(err) => match err { CallError::Runtime(RuntimeError::Unknown { msg }) => { assert!(!msg.contains("segmentation violation")); assert!(!msg.contains("bus error")); From d231d404cb668e094ad4dc23e80ab987a142fc37 Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 15:01:28 -0800 Subject: [PATCH 5/6] extern is no longer needed cause macro magic --- lib/spectests/examples/simple/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index 349c19d57..11dac23ba 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -59,7 +59,7 @@ fn main() -> Result<()> { Ok(()) } -extern "C" fn print_num(n: i32, ctx: &mut vm::Ctx) -> i32 { +fn print_num(n: i32, ctx: &mut vm::Ctx) -> i32 { println!("print_num({})", n); let memory = ctx.memory(0); From 6a7c78d65aa16779bd350837892599c5bf2b62ba Mon Sep 17 00:00:00 2001 From: Mackenzie Clark Date: Mon, 4 Feb 2019 15:01:43 -0800 Subject: [PATCH 6/6] this name should match the function name --- lib/spectests/examples/simple/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spectests/examples/simple/main.rs b/lib/spectests/examples/simple/main.rs index 11dac23ba..1ceaaf23f 100644 --- a/lib/spectests/examples/simple/main.rs +++ b/lib/spectests/examples/simple/main.rs @@ -38,7 +38,7 @@ fn main() -> Result<()> { let import_object = imports! { "env" => { - "print_i32" => func!(print_num, [i32] -> [i32]), + "print_num" => func!(print_num), "memory" => memory, "global" => global, "table" => table,