mirror of
https://github.com/fluencelabs/interface-types
synced 2024-12-04 07:10:21 +00:00
return error if allocate returns 0
This commit is contained in:
parent
39dca73210
commit
4a41d36c52
@ -20,6 +20,9 @@ use thiserror::Error as ThisError;
|
||||
|
||||
#[derive(Debug, ThisError)]
|
||||
pub enum LoError {
|
||||
#[error("Allocator of Wasm module returns 0 which means that it's out of memory")]
|
||||
AllocateWasInvalid,
|
||||
|
||||
#[error("{0}")]
|
||||
AllocatableError(#[from] AllocatableError),
|
||||
|
||||
|
@ -21,6 +21,7 @@ use crate::traits::DEFAULT_MEMORY_INDEX;
|
||||
use crate::utils::type_tag_form_itype;
|
||||
|
||||
use std::cell::Cell;
|
||||
use crate::lowerer::LoError;
|
||||
|
||||
pub struct MemoryWriter<'i, R: Allocatable> {
|
||||
heap_manager: &'i R,
|
||||
@ -54,6 +55,10 @@ impl<'i, A: Allocatable> MemoryWriter<'i, A> {
|
||||
|
||||
pub fn sequential_writer(&self, size: u32, type_tag: u32) -> LoResult<SequentialWriter> {
|
||||
let offset = self.heap_manager.allocate(size, type_tag)?;
|
||||
if offset == 0 {
|
||||
return Err(LoError::AllocateWasInvalid);
|
||||
}
|
||||
|
||||
let new_mem_slice = self.heap_manager.memory_slice(DEFAULT_MEMORY_INDEX)?;
|
||||
self.memory.set(new_mem_slice);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user