std: Apply unsafe_op_in_unsafe_fn

This commit is contained in:
Eric Huss 2025-02-13 12:51:22 -08:00
parent d5f0aa49e7
commit 4f4ea35a69
2 changed files with 5 additions and 5 deletions

View File

@ -20,11 +20,11 @@
//!
//! unsafe impl GlobalAlloc for MyAllocator {
//! unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
//! System.alloc(layout)
//! unsafe { System.alloc(layout) }
//! }
//!
//! unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
//! System.dealloc(ptr, layout)
//! unsafe { System.dealloc(ptr, layout) }
//! }
//! }
//!
@ -102,7 +102,7 @@ pub use alloc_crate::alloc::*;
///
/// unsafe impl GlobalAlloc for Counter {
/// unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
/// let ret = System.alloc(layout);
/// let ret = unsafe { System.alloc(layout) };
/// if !ret.is_null() {
/// ALLOCATED.fetch_add(layout.size(), Relaxed);
/// }
@ -110,7 +110,7 @@ pub use alloc_crate::alloc::*;
/// }
///
/// unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
/// System.dealloc(ptr, layout);
/// unsafe { System.dealloc(ptr, layout); }
/// ALLOCATED.fetch_sub(layout.size(), Relaxed);
/// }
/// }

View File

@ -56,7 +56,7 @@ impl Thread {
}
};
let ret = libc::pthread_create(&mut native, &attr, thread_start, p as *mut _);
let ret = unsafe { libc::pthread_create(&mut native, &attr, thread_start, p as *mut _) };
// Note: if the thread creation fails and this assert fails, then p will
// be leaked. However, an alternative design could cause double-free
// which is clearly worse.