From ac607ed2abdf0d51aedca302a78aa27d03451d2c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Sep 2024 12:44:45 -0500 Subject: [PATCH] Reduce some `unsafe` with APIs from Rust 1.79 (#9203) Notably `*mut [T]` now sports a `len` method to avoid the need for an `unsafe` block to read the length field. --- crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs | 4 ++-- crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs | 2 +- crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs | 4 ++-- crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs index 171cf010aee6..a9f46262709d 100644 --- a/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/custom/mmap.rs @@ -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( @@ -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; } diff --git a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs index de2a6aa3f76c..b4f834f3a466 100644 --- a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs @@ -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( diff --git a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs index 4c29a9ae1ca0..ad6f230e13c7 100644 --- a/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/unix/mmap.rs @@ -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( @@ -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; } diff --git a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs index d4d62061eb22..c0e6bc0efe99 100644 --- a/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/sys/windows/mmap.rs @@ -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(