mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
implement up to two slices in write_bytes (gather)
This commit is contained in:
parent
0d22a475f8
commit
cfaffd0ac2
@ -147,7 +147,10 @@ impl MemoryManager {
|
||||
store,
|
||||
memory,
|
||||
allocator,
|
||||
(
|
||||
&bincode::serialize(object).map_err(PluginModuleError::Encoding)?,
|
||||
&[],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@ -184,7 +187,7 @@ impl MemoryManager {
|
||||
<MemoryModel as wasmer::MemorySize>::Offset,
|
||||
WasmPtr<u8, MemoryModel>,
|
||||
>,
|
||||
bytes: &[u8],
|
||||
bytes: (&[u8], &[u8]),
|
||||
) -> Result<
|
||||
(
|
||||
WasmPtr<u8, MemoryModel>,
|
||||
@ -192,15 +195,22 @@ impl MemoryManager {
|
||||
),
|
||||
PluginModuleError,
|
||||
> {
|
||||
let len = bytes.len() as <MemoryModel as wasmer::MemorySize>::Offset;
|
||||
let len = (bytes.0.len() + bytes.1.len()) as <MemoryModel as wasmer::MemorySize>::Offset;
|
||||
let ptr = self
|
||||
.get_pointer(store, len, allocator)
|
||||
.map_err(PluginModuleError::MemoryAllocation)?;
|
||||
ptr.slice(
|
||||
&memory.view(store),
|
||||
bytes.len() as <MemoryModel as wasmer::MemorySize>::Offset,
|
||||
len as <MemoryModel as wasmer::MemorySize>::Offset,
|
||||
)
|
||||
.and_then(|s| s.write_slice(bytes))
|
||||
.and_then(|s| {
|
||||
if !bytes.1.is_empty() {
|
||||
s.subslice(0..bytes.0.len() as u64).write_slice(bytes.0)?;
|
||||
s.subslice(bytes.0.len() as u64..len).write_slice(bytes.1)
|
||||
} else {
|
||||
s.write_slice(bytes.0)
|
||||
}
|
||||
})
|
||||
.map_err(|_| PluginModuleError::InvalidPointer)?;
|
||||
Ok((ptr, len))
|
||||
}
|
||||
@ -221,9 +231,7 @@ impl MemoryManager {
|
||||
bytes: &[u8],
|
||||
) -> Result<WasmPtr<u8, MemoryModel>, PluginModuleError> {
|
||||
let len = bytes.len() as <MemoryModel as wasmer::MemorySize>::Offset;
|
||||
let new_bytes = [&len.to_le_bytes(), bytes].concat();
|
||||
// TODO: could make write_bytes take an IntoIterator to avoid this concat?
|
||||
self.write_bytes(store, memory, allocator, &new_bytes)
|
||||
self.write_bytes(store, memory, allocator, (&len.to_le_bytes(), &bytes))
|
||||
.map(|val| val.0)
|
||||
}
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ fn execute_raw(
|
||||
&mut module.store.as_store_mut(),
|
||||
&module.memory,
|
||||
&module.allocator,
|
||||
bytes,
|
||||
(bytes, &[]),
|
||||
)?;
|
||||
|
||||
// This gets the event function from module exports
|
||||
@ -270,26 +270,6 @@ fn execute_raw(
|
||||
result_len,
|
||||
)?;
|
||||
Ok(bytes)
|
||||
// Waiting for `multi-value` to be added to LLVM. So we encode a pointer to
|
||||
// a u128 that represent [u64; 2]
|
||||
|
||||
// let u128_pointer = from_i64(
|
||||
// function_result[0]
|
||||
// .i64()
|
||||
// .ok_or_else(PluginModuleError::InvalidArgumentType)?,
|
||||
// );
|
||||
|
||||
// let bytes = memory_manager::read_bytes(&module.memory, u128_pointer, 16);
|
||||
|
||||
// We read the return object and deserialize it
|
||||
|
||||
// The first 8 bytes are encoded as le and represent the pointer to the data
|
||||
// The next 8 bytes are encoded as le and represent the length of the data
|
||||
// Ok(memory_manager::read_bytes(
|
||||
// &module.memory,
|
||||
// u64::from_le_bytes(bytes[0..8].try_into().unwrap()),
|
||||
// u64::from_le_bytes(bytes[8..16].try_into().unwrap()),
|
||||
// ))
|
||||
}
|
||||
|
||||
fn retrieve_action(
|
||||
|
Loading…
Reference in New Issue
Block a user