about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorMike Hommey <mh@glandium.org>2018-05-31 16:10:01 +0900
committerSimon Sapin <simon.sapin@exyr.org>2018-06-11 13:47:23 -0700
commit3373204ac49ebdb7194020ea9c556ce87910f7b7 (patch)
tree051b58bf4a75f04dc771f1638003802295592a96 /src/liballoc
parentf6ab74b8e7efed01c1045773b6693f23f6ebd93c (diff)
downloadrust-3373204ac49ebdb7194020ea9c556ce87910f7b7.tar.gz
rust-3373204ac49ebdb7194020ea9c556ce87910f7b7.zip
Replace `impl GlobalAlloc for Global` with a set of free functions
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/alloc.rs48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs
index 102910f4198..8c2dda77226 100644
--- a/src/liballoc/alloc.rs
+++ b/src/liballoc/alloc.rs
@@ -49,37 +49,39 @@ pub type Heap = Global;
 #[allow(non_upper_case_globals)]
 pub const Heap: Global = Global;
 
-unsafe impl GlobalAlloc for Global {
-    #[inline]
-    unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
-        __rust_alloc(layout.size(), layout.align())
-    }
+#[unstable(feature = "allocator_api", issue = "32838")]
+#[inline]
+pub unsafe fn alloc(layout: Layout) -> *mut u8 {
+    __rust_alloc(layout.size(), layout.align())
+}
 
-    #[inline]
-    unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
-        __rust_dealloc(ptr, layout.size(), layout.align())
-    }
+#[unstable(feature = "allocator_api", issue = "32838")]
+#[inline]
+pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
+    __rust_dealloc(ptr, layout.size(), layout.align())
+}
 
-    #[inline]
-    unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
-        __rust_realloc(ptr, layout.size(), layout.align(), new_size)
-    }
+#[unstable(feature = "allocator_api", issue = "32838")]
+#[inline]
+pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
+    __rust_realloc(ptr, layout.size(), layout.align(), new_size)
+}
 
-    #[inline]
-    unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
-        __rust_alloc_zeroed(layout.size(), layout.align())
-    }
+#[unstable(feature = "allocator_api", issue = "32838")]
+#[inline]
+pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
+    __rust_alloc_zeroed(layout.size(), layout.align())
 }
 
 unsafe impl Alloc for Global {
     #[inline]
     unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
-        NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
+        NonNull::new(alloc(layout)).ok_or(AllocErr)
     }
 
     #[inline]
     unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout) {
-        GlobalAlloc::dealloc(self, ptr.as_ptr(), layout)
+        dealloc(ptr.as_ptr(), layout)
     }
 
     #[inline]
@@ -89,12 +91,12 @@ unsafe impl Alloc for Global {
                       new_size: usize)
                       -> Result<NonNull<u8>, AllocErr>
     {
-        NonNull::new(GlobalAlloc::realloc(self, ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
+        NonNull::new(realloc(ptr.as_ptr(), layout, new_size)).ok_or(AllocErr)
     }
 
     #[inline]
     unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
-        NonNull::new(GlobalAlloc::alloc_zeroed(self, layout)).ok_or(AllocErr)
+        NonNull::new(alloc_zeroed(layout)).ok_or(AllocErr)
     }
 }
 
@@ -108,7 +110,7 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
         align as *mut u8
     } else {
         let layout = Layout::from_size_align_unchecked(size, align);
-        let ptr = Global.alloc(layout);
+        let ptr = alloc(layout);
         if !ptr.is_null() {
             ptr
         } else {
@@ -126,7 +128,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
     // We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
     if size != 0 {
         let layout = Layout::from_size_align_unchecked(size, align);
-        Global.dealloc(ptr as *mut u8, layout);
+        dealloc(ptr as *mut u8, layout);
     }
 }