From 78997846638aeff23e2d6b252cb06f426a0106c7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 25 Sep 2019 22:32:53 -0700 Subject: [PATCH] Replace `println` error handling. Use `panic!` and log macros for error handling instead of `println!`. --- wasmtime-wasi-c/src/translate.rs | 10 +++++----- wasmtime-wasi/src/syscalls.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/wasmtime-wasi-c/src/translate.rs b/wasmtime-wasi-c/src/translate.rs index ea81c47989..d3dd1007c3 100644 --- a/wasmtime-wasi-c/src/translate.rs +++ b/wasmtime-wasi-c/src/translate.rs @@ -26,19 +26,19 @@ unsafe fn decode_ptr( let last = match (ptr as usize).checked_add(len - 1) { Some(sum) => sum, None => { - println!("!!! overflow"); + debug!("overflow in decode_ptr"); return Err(host::__WASI_EFAULT as host::__wasi_errno_t); } }; // Check for out of bounds. if last >= (*definition).current_length { - println!("!!! out of bounds"); + debug!("out of bounds in decode_ptr"); return Err(host::__WASI_EFAULT as host::__wasi_errno_t); } } // Check alignment. if (ptr as usize) % align != 0 { - println!("!!! bad alignment: {} % {}", ptr, align); + debug!("bad alignment in decode_ptr: {} % {}", ptr, align); return Err(host::__WASI_EINVAL as host::__wasi_errno_t); } // Ok, translate the address. @@ -47,8 +47,8 @@ unsafe fn decode_ptr( // No export named "memory", or the export isn't a memory. // FIXME: Is EINVAL the best code here? x => { - println!( - "!!! no export named \"memory\", or the export isn't a mem: {:?}", + error!( + "no export named \"memory\", or the export isn't a mem: {:?}", x ); Err(host::__WASI_EINVAL as host::__wasi_errno_t) diff --git a/wasmtime-wasi/src/syscalls.rs b/wasmtime-wasi/src/syscalls.rs index d6cf6e0f9d..7aa60d31e1 100644 --- a/wasmtime-wasi/src/syscalls.rs +++ b/wasmtime-wasi/src/syscalls.rs @@ -77,7 +77,7 @@ impl AbiRet for () { fn get_wasi_ctx(vmctx: &mut VMContext) -> Result<&mut WasiCtx, wasm32::__wasi_errno_t> { unsafe { vmctx.host_state().downcast_mut::().ok_or_else(|| { - println!("!!! no host state named WasiCtx available"); + panic!("no host state named WasiCtx available"); wasm32::__WASI_EINVAL }) } @@ -95,8 +95,8 @@ fn get_memory(vmctx: &mut VMContext) -> Result<&mut [u8], wasm32::__wasi_errno_t (*definition).current_length, )), x => { - println!( - "!!! no export named \"memory\", or the export isn't a mem: {:?}", + error!( + "no export named \"memory\", or the export isn't a mem: {:?}", x ); Err(wasm32::__WASI_EINVAL)