propogate changes to use anyhow::Error instead of Box<dyn Error...>
This commit is contained in:
@@ -551,7 +551,7 @@ impl Table {
|
||||
let init = init.into_table_element(store, ty)?;
|
||||
let table = self.wasmtime_table(store);
|
||||
unsafe {
|
||||
match (*table).grow(delta, init, store) {
|
||||
match (*table).grow(delta, init, store)? {
|
||||
Some(size) => {
|
||||
let vm = (*table).vmtable();
|
||||
*store[self.0].definition = vm;
|
||||
|
||||
@@ -4,8 +4,6 @@ use crate::{
|
||||
StoreContext, StoreContextMut, Trap, Val, ValRaw, ValType,
|
||||
};
|
||||
use anyhow::{bail, Context as _, Result};
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::mem;
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
@@ -1784,25 +1782,6 @@ impl<T> AsContextMut for Caller<'_, T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn cross_store_trap() -> Box<dyn Error + Send + Sync> {
|
||||
#[derive(Debug)]
|
||||
struct CrossStoreError;
|
||||
|
||||
impl Error for CrossStoreError {}
|
||||
|
||||
impl fmt::Display for CrossStoreError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"host function attempted to return cross-`Store` \
|
||||
value to Wasm",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box::new(CrossStoreError)
|
||||
}
|
||||
|
||||
macro_rules! impl_into_func {
|
||||
($num:tt $($args:ident)*) => {
|
||||
// Implement for functions without a leading `&Caller` parameter,
|
||||
@@ -1852,7 +1831,7 @@ macro_rules! impl_into_func {
|
||||
{
|
||||
enum CallResult<U> {
|
||||
Ok(U),
|
||||
Trap(Box<dyn Error + Send + Sync>),
|
||||
Trap(anyhow::Error),
|
||||
Panic(Box<dyn std::any::Any + Send>),
|
||||
}
|
||||
|
||||
@@ -1901,7 +1880,9 @@ macro_rules! impl_into_func {
|
||||
// can't assume it returned a value that is
|
||||
// compatible with this store.
|
||||
if !ret.compatible_with_store(caller.store.0) {
|
||||
CallResult::Trap(cross_store_trap())
|
||||
CallResult::Trap(anyhow::anyhow!(
|
||||
"host function attempted to return cross-`Store` value to Wasm"
|
||||
))
|
||||
} else {
|
||||
match ret.into_abi_for_ret(caller.store.0, retptr) {
|
||||
Ok(val) => CallResult::Ok(val),
|
||||
|
||||
@@ -479,7 +479,7 @@ impl Memory {
|
||||
let store = store.as_context_mut().0;
|
||||
let mem = self.wasmtime_memory(store);
|
||||
unsafe {
|
||||
match (*mem).grow(delta, store) {
|
||||
match (*mem).grow(delta, store)? {
|
||||
Some(size) => {
|
||||
let vm = (*mem).vmmemory();
|
||||
*store[self.0].definition = vm;
|
||||
|
||||
@@ -81,7 +81,6 @@ use anyhow::{bail, Result};
|
||||
use std::cell::UnsafeCell;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryFrom;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::marker;
|
||||
@@ -1527,7 +1526,12 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
||||
(&mut inner.externref_activations_table, &inner.modules)
|
||||
}
|
||||
|
||||
fn memory_growing(&mut self, current: usize, desired: usize, maximum: Option<usize>) -> bool {
|
||||
fn memory_growing(
|
||||
&mut self,
|
||||
current: usize,
|
||||
desired: usize,
|
||||
maximum: Option<usize>,
|
||||
) -> Result<bool, anyhow::Error> {
|
||||
// Need to borrow async_cx before the mut borrow of the limiter.
|
||||
// self.async_cx() panicks when used with a non-async store, so
|
||||
// wrap this in an option.
|
||||
@@ -1539,20 +1543,19 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
||||
};
|
||||
match self.limiter {
|
||||
Some(ResourceLimiterInner::Sync(ref mut limiter)) => {
|
||||
limiter(&mut self.data).memory_growing(current, desired, maximum)
|
||||
Ok(limiter(&mut self.data).memory_growing(current, desired, maximum))
|
||||
}
|
||||
#[cfg(feature = "async")]
|
||||
Some(ResourceLimiterInner::Async(ref mut limiter)) => unsafe {
|
||||
async_cx
|
||||
Ok(async_cx
|
||||
.expect("ResourceLimiterAsync requires async Store")
|
||||
.block_on(
|
||||
limiter(&mut self.data)
|
||||
.memory_growing(current, desired, maximum)
|
||||
.as_mut(),
|
||||
)
|
||||
.expect("FIXME idk how to deal with a trap here!")
|
||||
)?)
|
||||
},
|
||||
None => true,
|
||||
None => Ok(true),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1569,7 +1572,12 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn table_growing(&mut self, current: u32, desired: u32, maximum: Option<u32>) -> bool {
|
||||
fn table_growing(
|
||||
&mut self,
|
||||
current: u32,
|
||||
desired: u32,
|
||||
maximum: Option<u32>,
|
||||
) -> Result<bool, anyhow::Error> {
|
||||
// Need to borrow async_cx before the mut borrow of the limiter.
|
||||
// self.async_cx() panicks when used with a non-async store, so
|
||||
// wrap this in an option.
|
||||
@@ -1582,33 +1590,32 @@ unsafe impl<T> wasmtime_runtime::Store for StoreInner<T> {
|
||||
|
||||
match self.limiter {
|
||||
Some(ResourceLimiterInner::Sync(ref mut limiter)) => {
|
||||
limiter(&mut self.data).table_growing(current, desired, maximum)
|
||||
Ok(limiter(&mut self.data).table_growing(current, desired, maximum))
|
||||
}
|
||||
#[cfg(feature = "async")]
|
||||
Some(ResourceLimiterInner::Async(ref mut limiter)) => unsafe {
|
||||
async_cx
|
||||
Ok(async_cx
|
||||
.expect("ResourceLimiterAsync requires async Store")
|
||||
.block_on(
|
||||
limiter(&mut self.data)
|
||||
.table_growing(current, desired, maximum)
|
||||
.as_mut(),
|
||||
)
|
||||
.expect("FIXME idk how to deal with a trap here!")
|
||||
)?)
|
||||
},
|
||||
None => true,
|
||||
None => Ok(true),
|
||||
}
|
||||
}
|
||||
|
||||
fn out_of_gas(&mut self) -> Result<(), Box<dyn Error + Send + Sync>> {
|
||||
fn out_of_gas(&mut self) -> Result<(), anyhow::Error> {
|
||||
return match &mut self.out_of_gas_behavior {
|
||||
OutOfGas::Trap => Err(Box::new(OutOfGasError)),
|
||||
OutOfGas::Trap => Err(anyhow::Error::new(OutOfGasError)),
|
||||
#[cfg(feature = "async")]
|
||||
OutOfGas::InjectFuel {
|
||||
injection_count,
|
||||
fuel_to_inject,
|
||||
} => {
|
||||
if *injection_count == 0 {
|
||||
return Err(Box::new(OutOfGasError));
|
||||
return Err(anyhow::Error::new(OutOfGasError));
|
||||
}
|
||||
*injection_count -= 1;
|
||||
let fuel = *fuel_to_inject;
|
||||
|
||||
@@ -57,7 +57,7 @@ unsafe extern "C" fn stub_fn<F>(
|
||||
// call-site, which gets unwrapped in `Trap::from_runtime` later on as we
|
||||
// convert from the internal `Trap` type to our own `Trap` type in this
|
||||
// crate.
|
||||
Ok(Err(trap)) => wasmtime_runtime::raise_user_trap(Box::new(trap)),
|
||||
Ok(Err(trap)) => wasmtime_runtime::raise_user_trap(trap.into()),
|
||||
|
||||
// And finally if the imported function panicked, then we trigger the
|
||||
// form of unwinding that's safe to jump over wasm code on all
|
||||
|
||||
Reference in New Issue
Block a user