Fix fatal crash made in previous PR (#15)

This commit is contained in:
Valery Antopol 2022-02-18 01:39:21 +03:00 committed by GitHub
parent 0c5145aa37
commit 2a8f8925c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 79 additions and 33 deletions

2
Cargo.lock generated
View File

@ -280,7 +280,7 @@ checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "wasmer-interface-types-fl"
version = "0.21.0"
version = "0.21.1"
dependencies = [
"fluence-it-types",
"it-lilo",

View File

@ -1,6 +1,6 @@
[package]
name = "wasmer-interface-types-fl"
version = "0.21.0"
version = "0.21.1"
description = "WebAssembly Interface Types library for Wasmer"
license = "MIT"
authors = ["The Wasmer Engineering Team <engineering@wasmer.io>"]

View File

@ -17,14 +17,24 @@ use std::convert::TryInto;
pub(crate) fn array_lift_memory<Instance, Export, LocalImport, Memory, SequentialMemoryView>(
instruction: Instruction,
value_type: IType,
) -> crate::interpreter::ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView>
) -> crate::interpreter::ExecutableInstruction<
Instance,
Export,
LocalImport,
Memory,
SequentialMemoryView,
>
where
Export: crate::interpreter::wasm::structures::Export,
LocalImport: crate::interpreter::wasm::structures::LocalImport,
Memory: crate::interpreter::wasm::structures::Memory<SequentialMemoryView>,
SequentialMemoryView: for<'a> crate::interpreter::wasm::structures::SequentialMemoryView<'a>,
Instance:
crate::interpreter::wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView>,
Instance: crate::interpreter::wasm::structures::Instance<
Export,
LocalImport,
Memory,
SequentialMemoryView,
>,
{
#[allow(unused_imports)]
use crate::interpreter::stack::Stackable;
@ -84,14 +94,24 @@ where
pub(crate) fn array_lower_memory<Instance, Export, LocalImport, Memory, SequentialMemoryView>(
instruction: Instruction,
value_type: IType,
) -> crate::interpreter::ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView>
) -> crate::interpreter::ExecutableInstruction<
Instance,
Export,
LocalImport,
Memory,
SequentialMemoryView,
>
where
Export: crate::interpreter::wasm::structures::Export,
LocalImport: crate::interpreter::wasm::structures::LocalImport,
Memory: crate::interpreter::wasm::structures::Memory<SequentialMemoryView>,
SequentialMemoryView: for<'a> crate::interpreter::wasm::structures::SequentialMemoryView<'a>,
Instance:
crate::interpreter::wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView>,
Instance: crate::interpreter::wasm::structures::Instance<
Export,
LocalImport,
Memory,
SequentialMemoryView,
>,
{
#[allow(unused_imports)]
use crate::interpreter::stack::Stackable;

View File

@ -7,8 +7,8 @@ use crate::{
interpreter::Instruction,
};
use it_memory_traits::{SequentialReader, SequentialWriter};
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use it_memory_traits::{SequentialReader, SequentialWriter};
use std::convert::TryInto;
@ -54,10 +54,7 @@ executable_instruction!(
.sequential_reader(pointer, length)
.map_err(|e| InstructionError::from_memory_access(instruction.clone(), e))?;
let mut data = Vec::<u8>::with_capacity(length);
for index in 0..length {
data[index] = reader.read_u8();
}
let data = (0..length).map(|_| reader.read_u8()).collect::<Vec<_>>();
log::debug!("byte_array.lift_memory: pushing {:?} on the stack", data);
runtime.stack.push(IValue::ByteArray(data));

View File

@ -14,14 +14,24 @@ use std::convert::TryInto;
pub(crate) fn record_lift_memory<Instance, Export, LocalImport, Memory, SequentialMemoryView>(
record_type_id: u64,
instruction: Instruction,
) -> crate::interpreter::ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView>
) -> crate::interpreter::ExecutableInstruction<
Instance,
Export,
LocalImport,
Memory,
SequentialMemoryView,
>
where
Export: crate::interpreter::wasm::structures::Export,
LocalImport: crate::interpreter::wasm::structures::LocalImport,
Memory: crate::interpreter::wasm::structures::Memory<SequentialMemoryView>,
SequentialMemoryView: for<'a> crate::interpreter::wasm::structures::SequentialMemoryView<'a>,
Instance:
crate::interpreter::wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView>,
Instance: crate::interpreter::wasm::structures::Instance<
Export,
LocalImport,
Memory,
SequentialMemoryView,
>,
{
#[allow(unused_imports)]
use crate::interpreter::stack::Stackable;
@ -81,14 +91,24 @@ where
pub(crate) fn record_lower_memory<Instance, Export, LocalImport, Memory, SequentialMemoryView>(
record_type_id: u64,
instruction: Instruction,
) -> crate::interpreter::ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView>
) -> crate::interpreter::ExecutableInstruction<
Instance,
Export,
LocalImport,
Memory,
SequentialMemoryView,
>
where
Export: crate::interpreter::wasm::structures::Export,
LocalImport: crate::interpreter::wasm::structures::LocalImport,
Memory: crate::interpreter::wasm::structures::Memory<SequentialMemoryView>,
SequentialMemoryView: for<'a> crate::interpreter::wasm::structures::SequentialMemoryView<'a>,
Instance:
crate::interpreter::wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView>,
Instance: crate::interpreter::wasm::structures::Instance<
Export,
LocalImport,
Memory,
SequentialMemoryView,
>,
{
#[allow(unused_imports)]
use crate::interpreter::stack::Stackable;

View File

@ -7,8 +7,8 @@ use crate::{
interpreter::Instruction,
};
use it_memory_traits::{SequentialReader, SequentialWriter};
use it_lilo::traits::DEFAULT_MEMORY_INDEX;
use it_memory_traits::{SequentialReader, SequentialWriter};
use std::convert::TryInto;
@ -53,11 +53,7 @@ executable_instruction!(
.sequential_reader(pointer, length)
.map_err(|e| InstructionError::from_memory_access(instruction.clone(), e))?;
let mut data = Vec::<u8>::with_capacity(length);
for index in 0..length {
data[index] = reader.read_u8();
}
let data = (0..length).map(|_| reader.read_u8()).collect::<Vec<_>>();
let string = String::from_utf8(data)
.map_err(|error| InstructionError::from_error_kind(instruction.clone(), InstructionErrorKind::String(error)))?;

View File

@ -13,13 +13,21 @@ use std::{convert::TryFrom, marker::PhantomData};
/// Represents the `Runtime`, which is used by an adapter to execute
/// its instructions.
pub(crate) struct Runtime<'invocation, 'instance, Instance, Export, LocalImport, Memory, SequentialMemoryView>
where
pub(crate) struct Runtime<
'invocation,
'instance,
Instance,
Export,
LocalImport,
Memory,
SequentialMemoryView,
> where
Export: wasm::structures::Export + 'instance,
LocalImport: wasm::structures::LocalImport + 'instance,
Memory: wasm::structures::Memory<SequentialMemoryView> + 'instance,
SequentialMemoryView: (for<'a> wasm::structures::SequentialMemoryView<'a>),
Instance: wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView> + 'instance,
Instance:
wasm::structures::Instance<Export, LocalImport, Memory, SequentialMemoryView> + 'instance,
{
/// The invocation inputs are all the arguments received by an
/// adapter.
@ -38,10 +46,13 @@ where
/// Type alias for an executable instruction. It's an implementation
/// details, but an instruction is a boxed closure instance.
pub(crate) type ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView> = Box<
dyn Fn(&mut Runtime<Instance, Export, LocalImport, Memory, SequentialMemoryView>) -> InstructionResult<()>
+ Send,
>;
pub(crate) type ExecutableInstruction<Instance, Export, LocalImport, Memory, SequentialMemoryView> =
Box<
dyn Fn(
&mut Runtime<Instance, Export, LocalImport, Memory, SequentialMemoryView>,
) -> InstructionResult<()>
+ Send,
>;
/// An interpreter is the central piece of this crate. It is a set of
/// executable instructions. Each instruction takes the runtime as

View File

@ -6,7 +6,9 @@ use crate::IType;
use crate::IValue;
use std::rc::Rc;
pub use it_memory_traits::{Memory, SequentialMemoryView, SequentialReader, SequentialWriter, MemoryAccessError};
pub use it_memory_traits::{
Memory, MemoryAccessError, SequentialMemoryView, SequentialReader, SequentialWriter,
};
pub trait TypedIndex: Copy + Clone {
fn new(index: usize) -> Self;