From 695dee063bcd40f154bb27b7beafcb3d4dd775ac Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sat, 3 Jun 2017 14:54:08 -0700 Subject: rustc: Implement the #[global_allocator] attribute This PR is an implementation of [RFC 1974] which specifies a new method of defining a global allocator for a program. This obsoletes the old `#![allocator]` attribute and also removes support for it. [RFC 1974]: https://github.com/rust-lang/rfcs/pull/197 The new `#[global_allocator]` attribute solves many issues encountered with the `#![allocator]` attribute such as composition and restrictions on the crate graph itself. The compiler now has much more control over the ABI of the allocator and how it's implemented, allowing much more freedom in terms of how this feature is implemented. cc #27389 --- src/liballoc/btree/node.rs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/liballoc/btree') diff --git a/src/liballoc/btree/node.rs b/src/liballoc/btree/node.rs index 811174b331e..0eaff6f2192 100644 --- a/src/liballoc/btree/node.rs +++ b/src/liballoc/btree/node.rs @@ -48,7 +48,7 @@ use core::ptr::{self, Unique}; use core::slice; use boxed::Box; -use heap; +use heap::{Heap, Alloc, Layout}; const B: usize = 6; pub const MIN_LEN: usize = B - 1; @@ -254,11 +254,7 @@ impl Root { self.as_mut().as_leaf_mut().parent = ptr::null(); unsafe { - heap::deallocate( - top, - mem::size_of::>(), - mem::align_of::>() - ); + Heap.dealloc(top, Layout::new::>()); } } } @@ -445,7 +441,7 @@ impl NodeRef { > { let ptr = self.as_leaf() as *const LeafNode as *const u8 as *mut u8; let ret = self.ascend().ok(); - heap::deallocate(ptr, mem::size_of::>(), mem::align_of::>()); + Heap.dealloc(ptr, Layout::new::>()); ret } } @@ -466,11 +462,7 @@ impl NodeRef { > { let ptr = self.as_internal() as *const InternalNode as *const u8 as *mut u8; let ret = self.ascend().ok(); - heap::deallocate( - ptr, - mem::size_of::>(), - mem::align_of::>() - ); + Heap.dealloc(ptr, Layout::new::>()); ret } } @@ -1252,16 +1244,14 @@ impl<'a, K, V> Handle, K, V, marker::Internal>, marker:: ).correct_parent_link(); } - heap::deallocate( + Heap.dealloc( right_node.node.get() as *mut u8, - mem::size_of::>(), - mem::align_of::>() + Layout::new::>(), ); } else { - heap::deallocate( + Heap.dealloc( right_node.node.get() as *mut u8, - mem::size_of::>(), - mem::align_of::>() + Layout::new::>(), ); } -- cgit 1.4.1-3-g733a5