runtime: use anyhow::Error instead of Box<dyn std::error::Error...>
This commit is contained in:
@@ -193,8 +193,9 @@ pub unsafe extern "C" fn wasmtime_memory32_grow(
|
||||
let instance = (*vmctx).instance_mut();
|
||||
let memory_index = MemoryIndex::from_u32(memory_index);
|
||||
match instance.memory_grow(memory_index, delta) {
|
||||
Some(size_in_bytes) => size_in_bytes / (wasmtime_environ::WASM_PAGE_SIZE as usize),
|
||||
None => usize::max_value(),
|
||||
Ok(Some(size_in_bytes)) => size_in_bytes / (wasmtime_environ::WASM_PAGE_SIZE as usize),
|
||||
Ok(None) => usize::max_value(),
|
||||
Err(err) => crate::traphandlers::raise_user_trap(err),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,9 +221,11 @@ pub unsafe extern "C" fn wasmtime_table_grow(
|
||||
init_value.into()
|
||||
}
|
||||
};
|
||||
instance
|
||||
.table_grow(table_index, delta, element)
|
||||
.unwrap_or(-1_i32 as u32)
|
||||
match instance.table_grow(table_index, delta, element) {
|
||||
Ok(Some(r)) => r,
|
||||
Ok(None) => -1_i32 as u32,
|
||||
Err(err) => crate::traphandlers::raise_user_trap(err),
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of `table.fill`.
|
||||
@@ -436,15 +439,6 @@ pub unsafe extern "C" fn wasmtime_externref_global_set(
|
||||
drop(old);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Unimplemented(&'static str);
|
||||
impl std::error::Error for Unimplemented {}
|
||||
impl std::fmt::Display for Unimplemented {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> {
|
||||
write!(f, "unimplemented: {}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// Implementation of `memory.atomic.notify` for locally defined memories.
|
||||
pub unsafe extern "C" fn wasmtime_memory_atomic_notify(
|
||||
vmctx: *mut VMContext,
|
||||
@@ -460,9 +454,9 @@ pub unsafe extern "C" fn wasmtime_memory_atomic_notify(
|
||||
// just to be sure.
|
||||
let addr_to_check = addr.checked_add(4).unwrap();
|
||||
validate_atomic_addr(instance, memory, addr_to_check).and_then(|()| {
|
||||
Err(Trap::User(Box::new(Unimplemented(
|
||||
"wasm atomics (fn wasmtime_memory_atomic_notify) unsupported",
|
||||
))))
|
||||
Err(Trap::User(anyhow::anyhow!(
|
||||
"unimplemented: wasm atomics (fn wasmtime_memory_atomic_notify) unsupported",
|
||||
)))
|
||||
})
|
||||
};
|
||||
match result {
|
||||
@@ -486,9 +480,9 @@ pub unsafe extern "C" fn wasmtime_memory_atomic_wait32(
|
||||
// but we still double-check
|
||||
let addr_to_check = addr.checked_add(4).unwrap();
|
||||
validate_atomic_addr(instance, memory, addr_to_check).and_then(|()| {
|
||||
Err(Trap::User(Box::new(Unimplemented(
|
||||
"wasm atomics (fn wasmtime_memory_atomic_wait32) unsupported",
|
||||
))))
|
||||
Err(Trap::User(anyhow::anyhow!(
|
||||
"unimplemented: wasm atomics (fn wasmtime_memory_atomic_wait32) unsupported",
|
||||
)))
|
||||
})
|
||||
};
|
||||
match result {
|
||||
@@ -512,9 +506,9 @@ pub unsafe extern "C" fn wasmtime_memory_atomic_wait64(
|
||||
// but we still double-check
|
||||
let addr_to_check = addr.checked_add(8).unwrap();
|
||||
validate_atomic_addr(instance, memory, addr_to_check).and_then(|()| {
|
||||
Err(Trap::User(Box::new(Unimplemented(
|
||||
"wasm atomics (fn wasmtime_memory_atomic_wait64) unsupported",
|
||||
))))
|
||||
Err(Trap::User(anyhow::anyhow!(
|
||||
"unimplemented: wasm atomics (fn wasmtime_memory_atomic_wait64) unsupported",
|
||||
)))
|
||||
})
|
||||
};
|
||||
match result {
|
||||
|
||||
Reference in New Issue
Block a user