Skip to content

Commit

Permalink
Reduce some unsafe with APIs from Rust 1.79 (#9203)
Browse files Browse the repository at this point in the history
Notably `*mut [T]` now sports a `len` method to avoid the need for an
`unsafe` block to read the length field.
  • Loading branch information
alexcrichton authored Sep 9, 2024
1 parent 0bce096 commit ac607ed
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Mmap {

#[inline]
pub fn len(&self) -> usize {
unsafe { (*self.memory.as_ptr()).len() }
self.memory.as_ptr().len()
}

pub unsafe fn make_executable(
Expand Down Expand Up @@ -102,7 +102,7 @@ impl Drop for Mmap {
fn drop(&mut self) {
unsafe {
let ptr = self.memory.as_ptr().cast();
let len = (*self.memory.as_ptr()).len();
let len = self.memory.as_ptr().len();
if len == 0 {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Mmap {
}

pub fn len(&self) -> usize {
unsafe { (*self.memory.as_ptr()).len() }
self.memory.as_ptr().len()
}

pub unsafe fn make_executable(
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Mmap {

#[inline]
pub fn len(&self) -> usize {
unsafe { (*self.memory.as_ptr()).len() }
self.memory.as_ptr().len()
}

pub unsafe fn make_executable(
Expand Down Expand Up @@ -149,7 +149,7 @@ impl Drop for Mmap {
fn drop(&mut self) {
unsafe {
let ptr = self.memory.as_ptr().cast();
let len = (*self.memory.as_ptr()).len();
let len = self.memory.as_ptr().len();
if len == 0 {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Mmap {

#[inline]
pub fn len(&self) -> usize {
unsafe { (*self.memory.as_ptr()).len() }
self.memory.as_ptr().len()
}

pub unsafe fn make_executable(
Expand Down

0 comments on commit ac607ed

Please sign in to comment.