Allow access to memory_index and grow on Instance (#105)

* Changed `memory_grow` and `memory_index` in `Instance` struct to be `pub(crate)` and added the equivalent proxy methods to the `InstanceHandle` struct.
This commit is contained in:
Stefano Buliani
2019-04-16 19:59:54 -07:00
committed by Dan Gohman
parent a99107203e
commit 3351befb3b

View File

@@ -520,8 +520,7 @@ impl Instance {
}
/// Return the memory index for the given `VMMemoryDefinition`.
/// FIXME: Should this be pub(crate)?
pub fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex {
pub(crate) fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex {
let offsets = &self.offsets;
let begin = unsafe {
(&self.vmctx as *const VMContext as *const u8)
@@ -548,8 +547,11 @@ impl Instance {
///
/// Returns `None` if memory can't be grown by the specified amount
/// of pages.
/// FIXME: Should this be pub(crate)?
pub fn memory_grow(&mut self, memory_index: DefinedMemoryIndex, delta: u32) -> Option<u32> {
pub(crate) fn memory_grow(
&mut self,
memory_index: DefinedMemoryIndex,
delta: u32,
) -> Option<u32> {
let result = self
.memories
.get_mut(memory_index)
@@ -832,6 +834,19 @@ impl InstanceHandle {
pub fn host_state(&mut self) -> &mut Any {
self.instance_mut().host_state()
}
/// Return the memory index for the given `VMMemoryDefinition` in this instance.
pub fn memory_index(&self, memory: &VMMemoryDefinition) -> DefinedMemoryIndex {
self.instance().memory_index(memory)
}
/// Grow memory in this instance by the specified amount of pages.
///
/// Returns `None` if memory can't be grown by the specified amount
/// of pages.
pub fn memory_grow(&mut self, memory_index: DefinedMemoryIndex, delta: u32) -> Option<u32> {
self.instance_mut().memory_grow(memory_index, delta)
}
}
impl InstanceHandle {