Skip to content

Commit

Permalink
fix(api): Provide stub impls for new LinearMemory methods
Browse files Browse the repository at this point in the history
This reverts a breaking API change by providing stub implementations for
two new methods on LinearMemory (grow_at_least, reset).

The implementations return a new MemoryError::UnsupportedOperation.
Note: Since MemoryError is non-exhaustive, adding a new variant is
allowed.

We can make these methods required in a future major release if desired.

Closes #4392
  • Loading branch information
theduke committed Jan 8, 2024
1 parent e83428e commit ff335cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ pub enum MemoryError {
/// Returned when a shared memory is required, but the given memory is not shared.
#[error("The memory is not shared")]
MemoryNotShared,
/// Returned when trying to call a memory operation that is not supported by
/// the particular memory implementation.
#[error("tried to call an unsupported memory operation: {message}")]
UnsupportedOperation {
/// Message describing the unsupported operation.
message: String,
},
/// A user defined error value, used for error cases not listed above.
#[error("A user-defined error occurred: {0}")]
Generic(String),
Expand Down
12 changes: 10 additions & 2 deletions lib/vm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,10 +692,18 @@ where

/// Grows the memory to at least a minimum size. If the memory is already big enough
/// for the min size then this function does nothing
fn grow_at_least(&mut self, min_size: u64) -> Result<(), MemoryError>;
fn grow_at_least(&mut self, _min_size: u64) -> Result<(), MemoryError> {
Err(MemoryError::UnsupportedOperation {
message: "grow_at_least() is not supported".to_string(),
})
}

/// Resets the memory back to zero length
fn reset(&mut self) -> Result<(), MemoryError>;
fn reset(&mut self) -> Result<(), MemoryError> {
Err(MemoryError::UnsupportedOperation {
message: "reset() is not supported".to_string(),
})
}

/// Return a `VMMemoryDefinition` for exposing the memory to compiled wasm code.
fn vmmemory(&self) -> NonNull<VMMemoryDefinition>;
Expand Down

0 comments on commit ff335cb

Please sign in to comment.