From 4795b39502279c4388c595df85237661525c91db Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Thu, 8 Feb 2018 17:02:27 +0300 Subject: [PATCH] Use Pages::BYTE_SIZE for LINEAR_MEMORY_PAGE_SIZE --- src/memory.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index ba8145d..466ad1a 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -6,14 +6,14 @@ use std::rc::Rc; use std::cell::RefCell; use parity_wasm::elements::ResizableLimits; use Error; -use memory_units::{RoundUpTo, Pages, Bytes}; +use memory_units::{RoundUpTo, Pages, Bytes, ByteSize}; /// Size of a page of [linear memory][`MemoryInstance`] - 64KiB. /// /// The size of a memory is always a integer multiple of a page size. /// /// [`MemoryInstance`]: struct.MemoryInstance.html -pub const LINEAR_MEMORY_PAGE_SIZE: Bytes = Bytes(65536); +pub const LINEAR_MEMORY_PAGE_SIZE: Bytes = Pages::BYTE_SIZE; /// Maximal number of pages. const LINEAR_MEMORY_MAX_PAGES: Pages = Pages(65536); @@ -343,10 +343,9 @@ pub fn validate_memory(initial: Pages, maximum: Option) -> Result<(), Str #[cfg(test)] mod tests { - use super::{MemoryInstance, LINEAR_MEMORY_MAX_PAGES}; + use super::{MemoryInstance, LINEAR_MEMORY_PAGE_SIZE}; use Error; - use parity_wasm::elements::ResizableLimits; - use memory_units::Pages; + use memory_units::{Pages, Bytes}; #[test] fn alloc() { @@ -379,6 +378,11 @@ mod tests { } } + #[test] + fn ensure_page_size() { + assert_eq!(LINEAR_MEMORY_PAGE_SIZE, Bytes(65536)); + } + fn create_memory(initial_content: &[u8]) -> MemoryInstance { let mem = MemoryInstance::new(Pages(1), Some(Pages(1))); mem.set(0, initial_content).expect("Successful initialize the memory");