diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libstd/alloc.rs | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/libstd/alloc.rs')
| -rw-r--r-- | src/libstd/alloc.rs | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/src/libstd/alloc.rs b/src/libstd/alloc.rs index eccf8cabf22..7fd55af1694 100644 --- a/src/libstd/alloc.rs +++ b/src/libstd/alloc.rs @@ -61,9 +61,9 @@ #![stable(feature = "alloc_module", since = "1.28.0")] +use core::ptr::NonNull; use core::sync::atomic::{AtomicPtr, Ordering}; use core::{mem, ptr}; -use core::ptr::NonNull; use crate::sys_common::util::dumb_print; @@ -152,10 +152,12 @@ unsafe impl Alloc for System { } #[inline] - unsafe fn realloc(&mut self, - ptr: NonNull<u8>, - layout: Layout, - new_size: usize) -> Result<NonNull<u8>, AllocErr> { + unsafe fn realloc( + &mut self, + ptr: NonNull<u8>, + layout: Layout, + new_size: usize, + ) -> Result<NonNull<u8>, AllocErr> { NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr) } } @@ -191,11 +193,7 @@ pub fn set_alloc_error_hook(hook: fn(Layout)) { #[unstable(feature = "alloc_error_hook", issue = "51245")] pub fn take_alloc_error_hook() -> fn(Layout) { let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); - if hook.is_null() { - default_alloc_error_hook - } else { - unsafe { mem::transmute(hook) } - } + if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } } fn default_alloc_error_hook(layout: Layout) { @@ -208,13 +206,12 @@ fn default_alloc_error_hook(layout: Layout) { #[unstable(feature = "alloc_internals", issue = "none")] pub fn rust_oom(layout: Layout) -> ! { let hook = HOOK.load(Ordering::SeqCst); - let hook: fn(Layout) = if hook.is_null() { - default_alloc_error_hook - } else { - unsafe { mem::transmute(hook) } - }; + let hook: fn(Layout) = + if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; hook(layout); - unsafe { crate::sys::abort_internal(); } + unsafe { + crate::sys::abort_internal(); + } } #[cfg(not(test))] @@ -222,7 +219,7 @@ pub fn rust_oom(layout: Layout) -> ! { #[allow(unused_attributes)] #[unstable(feature = "alloc_internals", issue = "none")] pub mod __default_lib_allocator { - use super::{System, Layout, GlobalAlloc}; + use super::{GlobalAlloc, Layout, System}; // These magic symbol names are used as a fallback for implementing the // `__rust_alloc` etc symbols (see `src/liballoc/alloc.rs) when there is // no `#[global_allocator]` attribute. @@ -234,29 +231,29 @@ pub mod __default_lib_allocator { // ABI #[rustc_std_internal_symbol] - pub unsafe extern fn __rdl_alloc(size: usize, align: usize) -> *mut u8 { + pub unsafe extern "C" fn __rdl_alloc(size: usize, align: usize) -> *mut u8 { let layout = Layout::from_size_align_unchecked(size, align); System.alloc(layout) } #[rustc_std_internal_symbol] - pub unsafe extern fn __rdl_dealloc(ptr: *mut u8, - size: usize, - align: usize) { + pub unsafe extern "C" fn __rdl_dealloc(ptr: *mut u8, size: usize, align: usize) { System.dealloc(ptr, Layout::from_size_align_unchecked(size, align)) } #[rustc_std_internal_symbol] - pub unsafe extern fn __rdl_realloc(ptr: *mut u8, - old_size: usize, - align: usize, - new_size: usize) -> *mut u8 { + pub unsafe extern "C" fn __rdl_realloc( + ptr: *mut u8, + old_size: usize, + align: usize, + new_size: usize, + ) -> *mut u8 { let old_layout = Layout::from_size_align_unchecked(old_size, align); System.realloc(ptr, old_layout, new_size) } #[rustc_std_internal_symbol] - pub unsafe extern fn __rdl_alloc_zeroed(size: usize, align: usize) -> *mut u8 { + pub unsafe extern "C" fn __rdl_alloc_zeroed(size: usize, align: usize) -> *mut u8 { let layout = Layout::from_size_align_unchecked(size, align); System.alloc_zeroed(layout) } |
