Replace println error handling.

Use `panic!` and log macros for error handling instead of `println!`.
This commit is contained in:
Dan Gohman
2019-09-25 22:32:53 -07:00
parent 053fb3433e
commit 7899784663
2 changed files with 8 additions and 8 deletions

View File

@@ -26,19 +26,19 @@ unsafe fn decode_ptr(
let last = match (ptr as usize).checked_add(len - 1) { let last = match (ptr as usize).checked_add(len - 1) {
Some(sum) => sum, Some(sum) => sum,
None => { None => {
println!("!!! overflow"); debug!("overflow in decode_ptr");
return Err(host::__WASI_EFAULT as host::__wasi_errno_t); return Err(host::__WASI_EFAULT as host::__wasi_errno_t);
} }
}; };
// Check for out of bounds. // Check for out of bounds.
if last >= (*definition).current_length { 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); return Err(host::__WASI_EFAULT as host::__wasi_errno_t);
} }
} }
// Check alignment. // Check alignment.
if (ptr as usize) % align != 0 { 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); return Err(host::__WASI_EINVAL as host::__wasi_errno_t);
} }
// Ok, translate the address. // Ok, translate the address.
@@ -47,8 +47,8 @@ unsafe fn decode_ptr(
// No export named "memory", or the export isn't a memory. // No export named "memory", or the export isn't a memory.
// FIXME: Is EINVAL the best code here? // FIXME: Is EINVAL the best code here?
x => { x => {
println!( error!(
"!!! no export named \"memory\", or the export isn't a mem: {:?}", "no export named \"memory\", or the export isn't a mem: {:?}",
x x
); );
Err(host::__WASI_EINVAL as host::__wasi_errno_t) Err(host::__WASI_EINVAL as host::__wasi_errno_t)

View File

@@ -77,7 +77,7 @@ impl AbiRet for () {
fn get_wasi_ctx(vmctx: &mut VMContext) -> Result<&mut WasiCtx, wasm32::__wasi_errno_t> { fn get_wasi_ctx(vmctx: &mut VMContext) -> Result<&mut WasiCtx, wasm32::__wasi_errno_t> {
unsafe { unsafe {
vmctx.host_state().downcast_mut::<WasiCtx>().ok_or_else(|| { vmctx.host_state().downcast_mut::<WasiCtx>().ok_or_else(|| {
println!("!!! no host state named WasiCtx available"); panic!("no host state named WasiCtx available");
wasm32::__WASI_EINVAL wasm32::__WASI_EINVAL
}) })
} }
@@ -95,8 +95,8 @@ fn get_memory(vmctx: &mut VMContext) -> Result<&mut [u8], wasm32::__wasi_errno_t
(*definition).current_length, (*definition).current_length,
)), )),
x => { x => {
println!( error!(
"!!! no export named \"memory\", or the export isn't a mem: {:?}", "no export named \"memory\", or the export isn't a mem: {:?}",
x x
); );
Err(wasm32::__WASI_EINVAL) Err(wasm32::__WASI_EINVAL)