Skip to content

Commit 88ebd2d

Browse files
committed
Rename the Heap type to Global
… since it is the entry point for what’s registered with `#[global_allocator]`
1 parent 743c29b commit 88ebd2d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/liballoc/alloc.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,14 @@ extern "Rust" {
7777
}
7878

7979
#[derive(Copy, Clone, Default, Debug)]
80-
pub struct Heap;
80+
pub struct Global;
8181

82-
unsafe impl Alloc for Heap {
82+
#[unstable(feature = "allocator_api", issue = "32838")]
83+
#[rustc_deprecated(since = "1.27.0", reason = "type renamed to `Global`")]
84+
pub use self::Global as Heap;
85+
86+
87+
unsafe impl Alloc for Global {
8388
#[inline]
8489
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
8590
let mut err = ManuallyDrop::new(mem::uninitialized::<AllocErr>());
@@ -240,8 +245,8 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
240245
align as *mut u8
241246
} else {
242247
let layout = Layout::from_size_align_unchecked(size, align);
243-
Heap.alloc(layout).unwrap_or_else(|err| {
244-
Heap.oom(err)
248+
Global.alloc(layout).unwrap_or_else(|err| {
249+
Global.oom(err)
245250
})
246251
}
247252
}
@@ -254,7 +259,7 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) {
254259
// We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
255260
if size != 0 {
256261
let layout = Layout::from_size_align_unchecked(size, align);
257-
Heap.dealloc(ptr as *mut u8, layout);
262+
Global.dealloc(ptr as *mut u8, layout);
258263
}
259264
}
260265

@@ -263,22 +268,22 @@ mod tests {
263268
extern crate test;
264269
use self::test::Bencher;
265270
use boxed::Box;
266-
use heap::{Heap, Alloc, Layout};
271+
use heap::{Global, Alloc, Layout};
267272

268273
#[test]
269274
fn allocate_zeroed() {
270275
unsafe {
271276
let layout = Layout::from_size_align(1024, 1).unwrap();
272-
let ptr = Heap.alloc_zeroed(layout.clone())
273-
.unwrap_or_else(|e| Heap.oom(e));
277+
let ptr = Global.alloc_zeroed(layout.clone())
278+
.unwrap_or_else(|e| Global.oom(e));
274279

275280
let end = ptr.offset(layout.size() as isize);
276281
let mut i = ptr;
277282
while i < end {
278283
assert_eq!(*i, 0);
279284
i = i.offset(1);
280285
}
281-
Heap.dealloc(ptr, layout);
286+
Global.dealloc(ptr, layout);
282287
}
283288
}
284289

0 commit comments

Comments
 (0)