Skip to content

Commit

Permalink
Added back Memory::data_unchecked and Memory::data_unchecked_mut as h…
Browse files Browse the repository at this point in the history
…idden (for wit-bindgen)
  • Loading branch information
ptitSeb authored and epilys committed Jul 19, 2022
1 parent 593ab1d commit b101087
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lib/api/src/sys/externals/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,33 @@ impl Memory {
self.buffer(ctx).len.try_into().unwrap()
}

/// Retrieve a slice of the memory contents.
///
/// # Safety
///
/// Until the returned slice is dropped, it is undefined behaviour to
/// modify the memory contents in any way including by calling a wasm
/// function that writes to the memory or by resizing the memory.
#[doc(hidden)]
pub unsafe fn data_unchecked(&self, ctx: &impl AsStoreRef) -> &[u8] {
self.data_unchecked_mut(ctx)
}

/// Retrieve a mutable slice of the memory contents.
///
/// # Safety
///
/// This method provides interior mutability without an UnsafeCell. Until
/// the returned value is dropped, it is undefined behaviour to read or
/// write to the pointed-to memory in any way except through this slice,
/// including by calling a wasm function that reads the memory contents or
/// by resizing this Memory.
#[allow(clippy::mut_from_ref)]
#[doc(hidden)]
pub unsafe fn data_unchecked_mut(&self, ctx: &impl AsStoreRef) -> &mut [u8] {
slice::from_raw_parts_mut(self.buffer(ctx).base, self.buffer(ctx).len)
}

/// Returns the size (in [`Pages`]) of the `Memory`.
///
/// # Example
Expand Down

0 comments on commit b101087

Please sign in to comment.