Skip to content

fix: make {ModuleInstance,FuncContext}::exported_memory actually immutable #41

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/tinywasm/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ impl FuncContext<'_> {
}

/// Get a reference to an exported memory
pub fn exported_memory(&mut self, name: &str) -> Result<MemoryRef<'_>> {
pub fn exported_memory(&self, name: &str) -> Result<MemoryRef<'_>> {
self.module().exported_memory(self.store, name)
}

/// Get a reference to an exported memory
/// Get a mutable reference to an exported memory
pub fn exported_memory_mut(&mut self, name: &str) -> Result<MemoryRefMut<'_>> {
self.module().exported_memory_mut(self.store, name)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/tinywasm/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl ModuleInstance {
}

/// Get an exported memory by name
pub fn exported_memory<'a>(&self, store: &'a mut Store, name: &str) -> Result<MemoryRef<'a>> {
pub fn exported_memory<'a>(&self, store: &'a Store, name: &str) -> Result<MemoryRef<'a>> {
let export = self.export_addr(name).ok_or_else(|| Error::Other(format!("Export not found: {name}")))?;
let ExternVal::Memory(mem_addr) = export else {
return Err(Error::Other(format!("Export is not a memory: {name}")));
Expand All @@ -198,7 +198,7 @@ impl ModuleInstance {
self.memory(store, mem_addr)
}

/// Get an exported memory by name
/// Get an exported memory by name (mutable)
pub fn exported_memory_mut<'a>(&self, store: &'a mut Store, name: &str) -> Result<MemoryRefMut<'a>> {
let export = self.export_addr(name).ok_or_else(|| Error::Other(format!("Export not found: {name}")))?;
let ExternVal::Memory(mem_addr) = export else {
Expand Down