Remove some custom error types in Wasmtime (#5347)
* Remove some custom error types in Wasmtime These types are mostly cumbersome to work with nowadays that `anyhow` is used everywhere else. This commit removes `InstantiationError` and `SetupError` in favor of using `anyhow::Error` throughout. This can eventually culminate in creation of specific errors for embedders to downcast to but for now this should be general enough. * Fix Windows build
This commit is contained in:
@@ -5,13 +5,13 @@ use crate::{
|
||||
AsContextMut, Engine, Export, Extern, Func, Global, Memory, Module, SharedMemory,
|
||||
StoreContextMut, Table, TypedFunc,
|
||||
};
|
||||
use anyhow::{anyhow, bail, Context, Error, Result};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use std::mem;
|
||||
use std::sync::Arc;
|
||||
use wasmtime_environ::{EntityType, FuncIndex, GlobalIndex, MemoryIndex, PrimaryMap, TableIndex};
|
||||
use wasmtime_runtime::{
|
||||
Imports, InstanceAllocationRequest, InstantiationError, StorePtr, VMContext, VMFunctionBody,
|
||||
VMFunctionImport, VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTableImport,
|
||||
Imports, InstanceAllocationRequest, StorePtr, VMContext, VMFunctionBody, VMFunctionImport,
|
||||
VMGlobalImport, VMMemoryImport, VMOpaqueContext, VMTableImport,
|
||||
};
|
||||
|
||||
/// An instantiated WebAssembly module.
|
||||
@@ -317,20 +317,11 @@ impl Instance {
|
||||
// items from this instance into other instances should be ok when
|
||||
// those items are loaded and run we'll have all the metadata to
|
||||
// look at them.
|
||||
store
|
||||
.engine()
|
||||
.allocator()
|
||||
.initialize(
|
||||
&mut instance_handle,
|
||||
compiled_module.module(),
|
||||
store.engine().config().features.bulk_memory,
|
||||
)
|
||||
.map_err(|e| -> Error {
|
||||
match e {
|
||||
InstantiationError::Trap(trap) => trap.into(),
|
||||
other => other.into(),
|
||||
}
|
||||
})?;
|
||||
store.engine().allocator().initialize(
|
||||
&mut instance_handle,
|
||||
compiled_module.module(),
|
||||
store.engine().config().features.bulk_memory,
|
||||
)?;
|
||||
|
||||
Ok((instance, compiled_module.module().start_func))
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ use std::sync::Arc;
|
||||
use wasmtime_environ::{EntityIndex, MemoryPlan, MemoryStyle, Module, WASM_PAGE_SIZE};
|
||||
use wasmtime_runtime::{
|
||||
allocate_single_memory_instance, DefaultMemoryCreator, Imports, InstanceAllocationRequest,
|
||||
InstantiationError, Memory, MemoryImage, RuntimeLinearMemory, RuntimeMemoryCreator,
|
||||
SharedMemory, StorePtr, VMMemoryDefinition,
|
||||
Memory, MemoryImage, RuntimeLinearMemory, RuntimeMemoryCreator, SharedMemory, StorePtr,
|
||||
VMMemoryDefinition,
|
||||
};
|
||||
|
||||
/// Create a "frankenstein" instance with a single memory.
|
||||
@@ -48,8 +48,7 @@ pub fn create_memory(
|
||||
.as_mut()
|
||||
.expect("the store pointer cannot be null here")
|
||||
};
|
||||
Memory::new_dynamic(&plan, creator, store, None)
|
||||
.map_err(|err| InstantiationError::Resource(err.into()))?
|
||||
Memory::new_dynamic(&plan, creator, store, None)?
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user