mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-09 06:08:29 +00:00
Merge pull request #18 from wasmerio/fix/memory-not-growing
Debug memory not growing bug
This commit is contained in:
@@ -11,8 +11,8 @@ use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv,
|
||||
use wasmer_engine::Engine as _;
|
||||
use wasmer_runtime::{
|
||||
wasmer_call_trampoline, Export, ExportFunction, ExportGlobal, ExportMemory, ExportTable,
|
||||
LinearMemory, Table as RuntimeTable, VMCallerCheckedAnyfunc, VMContext, VMFunctionBody,
|
||||
VMGlobalDefinition, VMMemoryDefinition, VMTrampoline,
|
||||
LinearMemory, MemoryError, Table as RuntimeTable, VMCallerCheckedAnyfunc, VMContext,
|
||||
VMFunctionBody, VMGlobalDefinition, VMMemoryDefinition, VMTrampoline,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -344,25 +344,25 @@ pub struct Memory {
|
||||
}
|
||||
|
||||
impl Memory {
|
||||
pub fn new(store: &Store, ty: MemoryType) -> Memory {
|
||||
pub fn new(store: &Store, ty: MemoryType) -> Result<Memory, MemoryError> {
|
||||
let tunables = store.engine().tunables();
|
||||
let memory_plan = tunables.memory_plan(ty);
|
||||
let memory = tunables.create_memory(memory_plan).unwrap();
|
||||
let memory = tunables.create_memory(memory_plan)?;
|
||||
|
||||
let definition = memory.vmmemory();
|
||||
|
||||
Memory {
|
||||
Ok(Memory {
|
||||
store: store.clone(),
|
||||
owned_by_store: true,
|
||||
exported: ExportMemory {
|
||||
from: Box::leak(Box::new(memory)),
|
||||
definition: Box::leak(Box::new(definition)),
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn definition(&self) -> &VMMemoryDefinition {
|
||||
unsafe { &*self.exported.definition }
|
||||
fn definition(&self) -> VMMemoryDefinition {
|
||||
self.memory().vmmemory()
|
||||
}
|
||||
|
||||
pub fn ty(&self) -> &MemoryType {
|
||||
@@ -391,14 +391,14 @@ impl Memory {
|
||||
}
|
||||
|
||||
pub fn size(&self) -> Pages {
|
||||
Bytes(self.data_size()).into()
|
||||
self.memory().size()
|
||||
}
|
||||
|
||||
fn memory(&self) -> &LinearMemory {
|
||||
unsafe { &*self.exported.from }
|
||||
}
|
||||
|
||||
pub fn grow(&self, delta: Pages) -> Option<Pages> {
|
||||
pub fn grow(&self, delta: Pages) -> Result<Pages, MemoryError> {
|
||||
self.memory().grow(delta)
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ pub use wasmer_compiler::{Features, Target};
|
||||
pub use wasmer_engine::{
|
||||
DeserializeError, Engine, InstantiationError, LinkError, RuntimeError, SerializeError,
|
||||
};
|
||||
pub use wasmer_runtime::MemoryError;
|
||||
|
||||
// The compilers are mutually exclusive
|
||||
#[cfg(any(
|
||||
|
||||
@@ -3,6 +3,7 @@ use std::cmp::min;
|
||||
use target_lexicon::{OperatingSystem, PointerWidth, Triple, HOST};
|
||||
use wasm_common::{MemoryType, Pages, TableType};
|
||||
use wasmer_engine::Tunables as BaseTunables;
|
||||
use wasmer_runtime::MemoryError;
|
||||
use wasmer_runtime::{LinearMemory, Table};
|
||||
use wasmer_runtime::{MemoryPlan, MemoryStyle, TablePlan, TableStyle};
|
||||
|
||||
@@ -93,7 +94,7 @@ impl BaseTunables for Tunables {
|
||||
}
|
||||
|
||||
/// Create a memory given a memory type
|
||||
fn create_memory(&self, plan: MemoryPlan) -> Result<LinearMemory, String> {
|
||||
fn create_memory(&self, plan: MemoryPlan) -> Result<LinearMemory, MemoryError> {
|
||||
LinearMemory::new(&plan)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user