Fix linter

This commit is contained in:
ptitSeb
2022-08-18 16:58:04 +02:00
parent c7c1507b8b
commit f599df0240
17 changed files with 82 additions and 82 deletions

View File

@@ -101,7 +101,11 @@ impl Memory {
} }
/// Creates a new host `Memory` from provided JavaScript memory. /// Creates a new host `Memory` from provided JavaScript memory.
pub fn new_raw(store: &mut impl AsStoreMut, js_memory: js_sys::WebAssembly::Memory, ty: MemoryType) -> Result<Self, MemoryError> { pub fn new_raw(
store: &mut impl AsStoreMut,
js_memory: js_sys::WebAssembly::Memory,
ty: MemoryType,
) -> Result<Self, MemoryError> {
let vm_memory = VMMemory::new(js_memory, ty); let vm_memory = VMMemory::new(js_memory, ty);
Ok(Self::from_vm_export(store, vm_memory)) Ok(Self::from_vm_export(store, vm_memory))
} }

View File

@@ -182,27 +182,23 @@ impl Imports {
} }
pub struct ImportsIterator<'a> { pub struct ImportsIterator<'a> {
iter: std::collections::hash_map::Iter<'a, (String, String), Extern> iter: std::collections::hash_map::Iter<'a, (String, String), Extern>,
} }
impl<'a> ImportsIterator<'a> impl<'a> ImportsIterator<'a> {
{
fn new(imports: &'a Imports) -> Self { fn new(imports: &'a Imports) -> Self {
let iter = imports.map.iter(); let iter = imports.map.iter();
Self { iter } Self { iter }
} }
} }
impl<'a> Iterator impl<'a> Iterator for ImportsIterator<'a> {
for ImportsIterator<'a> {
type Item = (&'a str, &'a str, &'a Extern); type Item = (&'a str, &'a str, &'a Extern);
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.iter self.iter
.next() .next()
.map(|(k, v)| { .map(|(k, v)| (k.0.as_str(), k.1.as_str(), v))
(k.0.as_str(), k.1.as_str(), v)
})
} }
} }

View File

@@ -75,7 +75,7 @@ pub use crate::js::value::Value as Val;
pub mod vm { pub mod vm {
//! The `vm` module re-exports wasmer-vm types. //! The `vm` module re-exports wasmer-vm types.
pub use crate::js::export::VMMemory; pub use crate::js::export::VMMemory;
} }

View File

@@ -10,7 +10,7 @@ use std::mem::MaybeUninit;
use std::slice; use std::slice;
#[cfg(feature = "tracing")] #[cfg(feature = "tracing")]
use tracing::warn; use tracing::warn;
use wasmer_types::{Pages, LinearMemory}; use wasmer_types::{LinearMemory, Pages};
use wasmer_vm::{InternalStoreHandle, MemoryError, StoreHandle, VMExtern, VMMemory}; use wasmer_vm::{InternalStoreHandle, MemoryError, StoreHandle, VMExtern, VMMemory};
use super::MemoryView; use super::MemoryView;
@@ -63,7 +63,7 @@ impl Memory {
/// Create a memory object from an existing memory and attaches it to the store /// Create a memory object from an existing memory and attaches it to the store
pub fn new_from_existing(new_store: &mut impl AsStoreMut, memory: VMMemory) -> Self { pub fn new_from_existing(new_store: &mut impl AsStoreMut, memory: VMMemory) -> Self {
Self { Self {
handle: StoreHandle::new(new_store.objects_mut(), memory) handle: StoreHandle::new(new_store.objects_mut(), memory),
} }
} }
@@ -152,8 +152,7 @@ impl Memory {
/// Attempts to clone this memory (if its clonable) /// Attempts to clone this memory (if its clonable)
pub fn try_clone(&self, store: &impl AsStoreRef) -> Option<VMMemory> { pub fn try_clone(&self, store: &impl AsStoreRef) -> Option<VMMemory> {
let mem = self.handle.get(store.as_store_ref().objects()); let mem = self.handle.get(store.as_store_ref().objects());
mem.try_clone() mem.try_clone().map(|mem| mem.into())
.map(|mem| mem.into())
} }
pub(crate) fn to_vm_extern(&self) -> VMExtern { pub(crate) fn to_vm_extern(&self) -> VMExtern {

View File

@@ -4,7 +4,7 @@ use std::convert::TryInto;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use std::slice; use std::slice;
use wasmer_types::{Pages, LinearMemory}; use wasmer_types::{LinearMemory, Pages};
use super::memory::MemoryBuffer; use super::memory::MemoryBuffer;
use super::Memory; use super::Memory;

View File

@@ -58,7 +58,7 @@ pub mod vm {
pub use wasmer_vm::{ pub use wasmer_vm::{
MemoryError, MemoryStyle, TableStyle, VMExtern, VMMemory, VMMemoryDefinition, VMTable, MemoryError, MemoryStyle, TableStyle, VMExtern, VMMemory, VMMemoryDefinition, VMTable,
VMTableDefinition, VMTableDefinition,
}; };
} }

View File

@@ -1071,7 +1071,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
expected, expected,
timeout, timeout,
)?; )?;
state.push1(res); } state.push1(res);
}
Operator::MemoryAtomicNotify { memarg } => { Operator::MemoryAtomicNotify { memarg } => {
let heap_index = MemoryIndex::from_u32(memarg.memory); let heap_index = MemoryIndex::from_u32(memarg.memory);
let heap = state.get_heap(builder.func, memarg.memory, environ)?; let heap = state.get_heap(builder.func, memarg.memory, environ)?;
@@ -1079,8 +1080,8 @@ pub fn translate_operator<FE: FuncEnvironment + ?Sized>(
let addr = state.pop1(); // 32 (fixed) let addr = state.pop1(); // 32 (fixed)
let addr = fold_atomic_mem_addr(addr, memarg, I32, builder); let addr = fold_atomic_mem_addr(addr, memarg, I32, builder);
let res = let res =
environ.translate_atomic_notify(builder.cursor(), heap_index, heap, addr, count)?; environ.translate_atomic_notify(builder.cursor(), heap_index, heap, addr, count)?;
state.push1(res); state.push1(res);
} }
Operator::I32AtomicLoad { memarg } => { Operator::I32AtomicLoad { memarg } => {
translate_atomic_load(I32, I32, memarg, builder, state, environ)? translate_atomic_load(I32, I32, memarg, builder, state, environ)?

View File

@@ -4,7 +4,8 @@ use crate::LinkError;
use more_asserts::assert_ge; use more_asserts::assert_ge;
use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap}; use wasmer_types::entity::{BoxedSlice, EntityRef, PrimaryMap};
use wasmer_types::{ use wasmer_types::{
ExternType, FunctionIndex, ImportError, ImportIndex, MemoryIndex, ModuleInfo, TableIndex, LinearMemory, ExternType, FunctionIndex, ImportError, ImportIndex, LinearMemory, MemoryIndex, ModuleInfo,
TableIndex,
}; };
use wasmer_vm::{ use wasmer_vm::{

View File

@@ -1,8 +1,8 @@
// This file contains code from external sources. // This file contains code from external sources.
// Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md // Attributions: https://github.com/wasmerio/wasmer/blob/master/ATTRIBUTIONS.md
use super::state::ModuleTranslationState; use super::state::ModuleTranslationState;
use crate::lib::std::string::ToString;
use crate::lib::std::borrow::ToOwned; use crate::lib::std::borrow::ToOwned;
use crate::lib::std::string::ToString;
use crate::lib::std::{boxed::Box, string::String, vec::Vec}; use crate::lib::std::{boxed::Box, string::String, vec::Vec};
use crate::translate_module; use crate::translate_module;
use crate::wasmparser::{Operator, Range, Type}; use crate::wasmparser::{Operator, Range, Type};

View File

@@ -76,8 +76,8 @@ pub use crate::compilation::target::{
}; };
pub use crate::serialize::{MetadataHeader, SerializableCompilation, SerializableModule}; pub use crate::serialize::{MetadataHeader, SerializableCompilation, SerializableModule};
pub use error::{ pub use error::{
CompileError, DeserializeError, ImportError, MiddlewareError, ParseCpuFeatureError, CompileError, DeserializeError, ImportError, MemoryError, MiddlewareError,
PreInstantiationError, SerializeError, WasmError, WasmResult, MemoryError, ParseCpuFeatureError, PreInstantiationError, SerializeError, WasmError, WasmResult,
}; };
/// The entity module, with common helpers for Rust structures /// The entity module, with common helpers for Rust structures
@@ -103,9 +103,7 @@ pub use types::{
pub use value::{RawValue, ValueType}; pub use value::{RawValue, ValueType};
pub use crate::libcalls::LibCall; pub use crate::libcalls::LibCall;
pub use crate::memory::{ pub use crate::memory::{LinearMemory, MemoryStyle, VMMemoryDefinition};
MemoryStyle, LinearMemory, VMMemoryDefinition
};
pub use crate::table::TableStyle; pub use crate::table::TableStyle;
pub use crate::trapcode::TrapCode; pub use crate::trapcode::TrapCode;
pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets}; pub use crate::vmoffsets::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};

View File

@@ -1,14 +1,14 @@
use crate::{Pages, ValueType}; use crate::{Pages, ValueType};
use core::ptr::NonNull;
use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; use rkyv::{Archive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize};
#[cfg(feature = "enable-serde")] #[cfg(feature = "enable-serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use core::ptr::NonNull;
use std::convert::{TryFrom, TryInto}; use std::convert::{TryFrom, TryInto};
use std::iter::Sum; use std::iter::Sum;
use std::ops::{Add, AddAssign}; use std::ops::{Add, AddAssign};
use super::MemoryType;
use super::MemoryError; use super::MemoryError;
use super::MemoryType;
/// Implementation styles for WebAssembly linear memory. /// Implementation styles for WebAssembly linear memory.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, RkyvSerialize, RkyvDeserialize, Archive)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, RkyvSerialize, RkyvDeserialize, Archive)]
@@ -132,7 +132,8 @@ unsafe impl MemorySize for Memory64 {
/// Represents memory that is used by the WebAsssembly module /// Represents memory that is used by the WebAsssembly module
pub trait LinearMemory pub trait LinearMemory
where Self: std::fmt::Debug + Send where
Self: std::fmt::Debug + Send,
{ {
/// Returns the type for this memory. /// Returns the type for this memory.
fn ty(&self) -> MemoryType; fn ty(&self) -> MemoryType;
@@ -183,10 +184,10 @@ unsafe impl Sync for VMMemoryDefinition {}
#[cfg(test)] #[cfg(test)]
mod test_vmmemory_definition { mod test_vmmemory_definition {
use super::VMMemoryDefinition; use super::VMMemoryDefinition;
use crate::ModuleInfo;
use crate::VMOffsets; use crate::VMOffsets;
use memoffset::offset_of; use memoffset::offset_of;
use std::mem::size_of; use std::mem::size_of;
use crate::ModuleInfo;
#[test] #[test]
fn check_vmmemory_definition_offsets() { fn check_vmmemory_definition_offsets() {

View File

@@ -5,8 +5,8 @@ use std::convert::TryFrom;
use std::mem; use std::mem;
use std::ptr::{self, NonNull}; use std::ptr::{self, NonNull};
use wasmer_types::entity::EntityRef; use wasmer_types::entity::EntityRef;
use wasmer_types::{VMOffsets, VMMemoryDefinition};
use wasmer_types::{LocalMemoryIndex, LocalTableIndex, ModuleInfo}; use wasmer_types::{LocalMemoryIndex, LocalTableIndex, ModuleInfo};
use wasmer_types::{VMMemoryDefinition, VMOffsets};
/// This is an intermediate type that manages the raw allocation and /// This is an intermediate type that manages the raw allocation and
/// metadata when creating an [`Instance`]. /// metadata when creating an [`Instance`].

View File

@@ -14,9 +14,9 @@ use crate::store::{InternalStoreHandle, StoreObjects};
use crate::table::TableElement; use crate::table::TableElement;
use crate::trap::{catch_traps, Trap, TrapCode}; use crate::trap::{catch_traps, Trap, TrapCode};
use crate::vmcontext::{ use crate::vmcontext::{
VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext, VMFunctionContext, memory_copy, memory_fill, VMBuiltinFunctionsArray, VMCallerCheckedAnyfunc, VMContext,
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMFunctionContext, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport,
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline, memory_copy, memory_fill, VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
}; };
use crate::{FunctionBodyPtr, MaybeInstanceOwned, TrapHandlerFn, VMFunctionBody}; use crate::{FunctionBodyPtr, MaybeInstanceOwned, TrapHandlerFn, VMFunctionBody};
use crate::{VMFuncRef, VMFunction, VMGlobal, VMMemory, VMTable}; use crate::{VMFuncRef, VMFunction, VMGlobal, VMMemory, VMTable};
@@ -35,9 +35,9 @@ use std::sync::Arc;
use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap}; use wasmer_types::entity::{packed_option::ReservedValue, BoxedSlice, EntityRef, PrimaryMap};
use wasmer_types::{ use wasmer_types::{
DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit, DataIndex, DataInitializer, ElemIndex, ExportIndex, FunctionIndex, GlobalIndex, GlobalInit,
LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryIndex, LinearMemory, LocalFunctionIndex, LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex,
ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer, VMOffsets, LinearMemory, MemoryError, MemoryIndex, ModuleInfo, Pages, SignatureIndex, TableIndex, TableInitializer,
MemoryError, VMMemoryDefinition VMMemoryDefinition, VMOffsets,
}; };
/// A WebAssembly instance. /// A WebAssembly instance.

View File

@@ -46,7 +46,6 @@ pub use crate::global::*;
pub use crate::imports::Imports; pub use crate::imports::Imports;
pub use crate::instance::{InstanceAllocator, InstanceHandle}; pub use crate::instance::{InstanceAllocator, InstanceHandle};
pub use crate::memory::VMMemory; pub use crate::memory::VMMemory;
pub use wasmer_types::MemoryError;
pub use crate::mmap::Mmap; pub use crate::mmap::Mmap;
pub use crate::probestack::PROBESTACK; pub use crate::probestack::PROBESTACK;
pub use crate::sig_registry::SignatureRegistry; pub use crate::sig_registry::SignatureRegistry;
@@ -57,13 +56,14 @@ pub use crate::table::{TableElement, VMTable};
pub use crate::trap::*; pub use crate::trap::*;
pub use crate::vmcontext::{ pub use crate::vmcontext::{
VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext, VMCallerCheckedAnyfunc, VMContext, VMDynamicFunctionContext, VMFunctionContext,
VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMFunctionImport, VMFunctionKind, VMGlobalDefinition, VMGlobalImport, VMMemoryImport,
VMMemoryImport, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline, VMSharedSignatureIndex, VMTableDefinition, VMTableImport, VMTrampoline,
}; };
pub use wasmer_types::LibCall; pub use wasmer_types::LibCall;
pub use wasmer_types::{MemoryStyle, VMMemoryDefinition}; pub use wasmer_types::MemoryError;
use wasmer_types::RawValue; use wasmer_types::RawValue;
pub use wasmer_types::TableStyle; pub use wasmer_types::TableStyle;
pub use wasmer_types::{MemoryStyle, VMMemoryDefinition};
pub use wasmer_types::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets}; pub use wasmer_types::{TargetSharedSignatureIndex, VMBuiltinFunctionIndex, VMOffsets};
#[deprecated( #[deprecated(

View File

@@ -10,7 +10,9 @@ use more_asserts::assert_ge;
use std::cell::UnsafeCell; use std::cell::UnsafeCell;
use std::convert::TryInto; use std::convert::TryInto;
use std::ptr::NonNull; use std::ptr::NonNull;
use wasmer_types::{Bytes, MemoryStyle, MemoryType, Pages, MemoryError, LinearMemory, VMMemoryDefinition}; use wasmer_types::{
Bytes, LinearMemory, MemoryError, MemoryStyle, MemoryType, Pages, VMMemoryDefinition,
};
// The memory mapped area // The memory mapped area
#[derive(Debug)] #[derive(Debug)]
@@ -23,8 +25,7 @@ struct WasmMmap {
vm_memory_definition: MaybeInstanceOwned<VMMemoryDefinition>, vm_memory_definition: MaybeInstanceOwned<VMMemoryDefinition>,
} }
impl WasmMmap impl WasmMmap {
{
fn get_vm_memory_definition(&self) -> NonNull<VMMemoryDefinition> { fn get_vm_memory_definition(&self) -> NonNull<VMMemoryDefinition> {
self.vm_memory_definition.as_ptr() self.vm_memory_definition.as_ptr()
} }
@@ -92,14 +93,12 @@ impl WasmMmap
Mmap::accessible_reserved(new_bytes, request_bytes).map_err(MemoryError::Region)?; Mmap::accessible_reserved(new_bytes, request_bytes).map_err(MemoryError::Region)?;
let copy_len = self.alloc.len() - conf.offset_guard_size; let copy_len = self.alloc.len() - conf.offset_guard_size;
new_mmap.as_mut_slice()[..copy_len] new_mmap.as_mut_slice()[..copy_len].copy_from_slice(&self.alloc.as_slice()[..copy_len]);
.copy_from_slice(&self.alloc.as_slice()[..copy_len]);
self.alloc = new_mmap; self.alloc = new_mmap;
} else if delta_bytes > 0 { } else if delta_bytes > 0 {
// Make the newly allocated pages accessible. // Make the newly allocated pages accessible.
self self.alloc
.alloc
.make_accessible(prev_bytes, delta_bytes) .make_accessible(prev_bytes, delta_bytes)
.map_err(MemoryError::Region)?; .map_err(MemoryError::Region)?;
} }
@@ -132,8 +131,7 @@ struct VMMemoryConfig {
offset_guard_size: usize, offset_guard_size: usize,
} }
impl VMMemoryConfig impl VMMemoryConfig {
{
fn ty(&self, minimum: Pages) -> MemoryType { fn ty(&self, minimum: Pages) -> MemoryType {
let mut out = self.memory; let mut out = self.memory;
out.minimum = minimum; out.minimum = minimum;
@@ -155,8 +153,8 @@ pub struct VMOwnedMemory {
config: VMMemoryConfig, config: VMMemoryConfig,
} }
unsafe impl Send for VMOwnedMemory { } unsafe impl Send for VMOwnedMemory {}
unsafe impl Sync for VMOwnedMemory { } unsafe impl Sync for VMOwnedMemory {}
impl VMOwnedMemory { impl VMOwnedMemory {
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages. /// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
@@ -248,7 +246,7 @@ impl VMOwnedMemory {
alloc, alloc,
size: memory.minimum, size: memory.minimum,
}; };
Ok(Self { Ok(Self {
mmap: mmap, mmap: mmap,
config: VMMemoryConfig { config: VMMemoryConfig {
@@ -256,14 +254,12 @@ impl VMOwnedMemory {
offset_guard_size: offset_guard_bytes, offset_guard_size: offset_guard_bytes,
memory: *memory, memory: *memory,
style: style.clone(), style: style.clone(),
} },
}) })
} }
} }
impl LinearMemory impl LinearMemory for VMOwnedMemory {
for VMOwnedMemory
{
/// Returns the type for this memory. /// Returns the type for this memory.
fn ty(&self) -> MemoryType { fn ty(&self) -> MemoryType {
let minimum = self.mmap.size(); let minimum = self.mmap.size();
@@ -299,9 +295,7 @@ for VMOwnedMemory
} }
} }
impl Into<VMMemory> impl Into<VMMemory> for VMOwnedMemory {
for VMOwnedMemory
{
fn into(self) -> VMMemory { fn into(self) -> VMMemory {
VMMemory(Box::new(self)) VMMemory(Box::new(self))
} }
@@ -311,17 +305,13 @@ for VMOwnedMemory
#[derive(Debug)] #[derive(Debug)]
pub struct VMMemory(Box<dyn LinearMemory + 'static>); pub struct VMMemory(Box<dyn LinearMemory + 'static>);
impl Into<VMMemory> impl Into<VMMemory> for Box<dyn LinearMemory + 'static> {
for Box<dyn LinearMemory + 'static>
{
fn into(self) -> VMMemory { fn into(self) -> VMMemory {
VMMemory(self) VMMemory(self)
} }
} }
impl LinearMemory impl LinearMemory for VMMemory {
for VMMemory
{
/// Returns the type for this memory. /// Returns the type for this memory.
fn ty(&self) -> MemoryType { fn ty(&self) -> MemoryType {
self.0.ty() self.0.ty()
@@ -356,17 +346,14 @@ for VMMemory
} }
} }
impl VMMemory impl VMMemory {
{
/// Creates a new linear memory instance of the correct type with specified /// Creates a new linear memory instance of the correct type with specified
/// minimum and maximum number of wasm pages. /// minimum and maximum number of wasm pages.
/// ///
/// This creates a `Memory` with owned metadata: this can be used to create a memory /// This creates a `Memory` with owned metadata: this can be used to create a memory
/// that will be imported into Wasm modules. /// that will be imported into Wasm modules.
pub fn new(memory: &MemoryType, style: &MemoryStyle) -> Result<VMMemory, MemoryError> { pub fn new(memory: &MemoryType, style: &MemoryStyle) -> Result<VMMemory, MemoryError> {
Ok( Ok(Self(Box::new(VMOwnedMemory::new(memory, style)?)))
Self(Box::new(VMOwnedMemory::new(memory, style)?))
)
} }
/// Create a new linear memory instance with specified minimum and maximum number of wasm pages. /// Create a new linear memory instance with specified minimum and maximum number of wasm pages.
@@ -381,9 +368,11 @@ impl VMMemory
style: &MemoryStyle, style: &MemoryStyle,
vm_memory_location: NonNull<VMMemoryDefinition>, vm_memory_location: NonNull<VMMemoryDefinition>,
) -> Result<VMMemory, MemoryError> { ) -> Result<VMMemory, MemoryError> {
Ok( Ok(Self(Box::new(VMOwnedMemory::from_definition(
Self(Box::new(VMOwnedMemory::from_definition(memory, style, vm_memory_location)?)) memory,
) style,
vm_memory_location,
)?)))
} }
/// Creates VMMemory from a custom implementation - the following into implementations /// Creates VMMemory from a custom implementation - the following into implementations
@@ -392,7 +381,8 @@ impl VMMemory
/// - VMSharedMemory -> VMMemory /// - VMSharedMemory -> VMMemory
/// - Box<dyn LinearMemory + 'static> -> VMMemory /// - Box<dyn LinearMemory + 'static> -> VMMemory
pub fn from_custom<IntoVMMemory>(memory: IntoVMMemory) -> VMMemory pub fn from_custom<IntoVMMemory>(memory: IntoVMMemory) -> VMMemory
where IntoVMMemory: Into<VMMemory> where
IntoVMMemory: Into<VMMemory>,
{ {
memory.into() memory.into()
} }

View File

@@ -267,9 +267,9 @@ impl<T> MaybeInstanceOwned<T> {
} }
} }
impl<T> std::fmt::Debug impl<T> std::fmt::Debug for MaybeInstanceOwned<T>
for MaybeInstanceOwned<T> where
where T: std::fmt::Debug T: std::fmt::Debug,
{ {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
@@ -277,7 +277,7 @@ where T: std::fmt::Debug
write!(f, "host(")?; write!(f, "host(")?;
p.as_ref().fmt(f)?; p.as_ref().fmt(f)?;
write!(f, ")") write!(f, ")")
}, }
MaybeInstanceOwned::Instance(p) => { MaybeInstanceOwned::Instance(p) => {
write!(f, "instance(")?; write!(f, "instance(")?;
unsafe { p.as_ref().fmt(f)? }; unsafe { p.as_ref().fmt(f)? };
@@ -285,4 +285,4 @@ where T: std::fmt::Debug
} }
} }
} }
} }

View File

@@ -313,7 +313,12 @@ mod test_vmglobal_import {
/// # Safety /// # Safety
/// The memory is not copied atomically and is not synchronized: it's the /// The memory is not copied atomically and is not synchronized: it's the
/// caller's responsibility to synchronize. /// caller's responsibility to synchronize.
pub(crate) unsafe fn memory_copy(mem: &VMMemoryDefinition, dst: u32, src: u32, len: u32) -> Result<(), Trap> { pub(crate) unsafe fn memory_copy(
mem: &VMMemoryDefinition,
dst: u32,
src: u32,
len: u32,
) -> Result<(), Trap> {
// https://webassembly.github.io/reference-types/core/exec/instructions.html#exec-memory-copy // https://webassembly.github.io/reference-types/core/exec/instructions.html#exec-memory-copy
if src if src
.checked_add(len) .checked_add(len)
@@ -347,7 +352,12 @@ pub(crate) unsafe fn memory_copy(mem: &VMMemoryDefinition, dst: u32, src: u32, l
/// # Safety /// # Safety
/// The memory is not filled atomically and is not synchronized: it's the /// The memory is not filled atomically and is not synchronized: it's the
/// caller's responsibility to synchronize. /// caller's responsibility to synchronize.
pub(crate) unsafe fn memory_fill(mem: &VMMemoryDefinition, dst: u32, val: u32, len: u32) -> Result<(), Trap> { pub(crate) unsafe fn memory_fill(
mem: &VMMemoryDefinition,
dst: u32,
val: u32,
len: u32,
) -> Result<(), Trap> {
if dst if dst
.checked_add(len) .checked_add(len)
.map_or(true, |m| usize::try_from(m).unwrap() > mem.current_length) .map_or(true, |m| usize::try_from(m).unwrap() > mem.current_length)