From b10108795aa7cdb05df29c5b1a7a2e4918bed0f3 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 13 Jul 2022 15:46:42 +0200 Subject: [PATCH] Added back Memory::data_unchecked and Memory::data_unchecked_mut as hidden (for wit-bindgen) --- lib/api/src/sys/externals/memory.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/api/src/sys/externals/memory.rs b/lib/api/src/sys/externals/memory.rs index 45b093c5070..ae682740452 100644 --- a/lib/api/src/sys/externals/memory.rs +++ b/lib/api/src/sys/externals/memory.rs @@ -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