next potion of tests added

This commit is contained in:
Svyatoslav Nikolsky
2017-06-09 12:13:35 +03:00
parent 0f1d63d77e
commit c8614bf6fe
10 changed files with 126 additions and 52 deletions

View File

@ -7,6 +7,8 @@ use interpreter::module::check_limits;
/// Linear memory page size.
pub const LINEAR_MEMORY_PAGE_SIZE: u32 = 65536;
/// Maximal number of pages.
const LINEAR_MEMORY_MAX_PAGES: u32 = 65536;
/// Linear memory instance.
pub struct MemoryInstance {
@ -21,6 +23,12 @@ impl MemoryInstance {
pub fn new(memory_type: &MemoryType) -> Result<Arc<Self>, Error> {
check_limits(memory_type.limits())?;
if let Some(maximum_pages) = memory_type.limits().maximum() {
if maximum_pages > LINEAR_MEMORY_MAX_PAGES {
return Err(Error::Memory(format!("memory size must be at most 65536 pages")));
}
}
let memory = MemoryInstance {
buffer: RwLock::new(Vec::new()), // TODO: with_capacity
maximum_size: memory_type.limits().maximum()
@ -64,7 +72,7 @@ impl MemoryInstance {
};
let mut buffer = self.buffer.write();
if buffer.len() <= end {
if buffer.len() < end {
return Err(Error::Memory(format!("trying to update region [{}..{}] in memory [0..{}]", begin, end, buffer.len())));
}