]> git.lizzy.rs Git - rust.git/blobdiff - src/libstd/alloc.rs
Auto merge of #67731 - matthewjasper:drop-in-place-reclimit, r=eddyb
[rust.git] / src / libstd / alloc.rs
index eccf8cabf220658189ac5f5c5a6909a45bcd1d77..7fd55af16941564ea8fb3d103c9abd559b553920 100644 (file)
@@ -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 fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
     }
 
     #[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)
     }