Stablize the GlobalAlloc trait

Fixes https://github.com/rust-lang/rust/issues/49668
This commit is contained in:
Simon Sapin 2018-05-31 19:13:18 +02:00
parent 77606f20c9
commit bbaff036e7

View File

@ -467,7 +467,7 @@ impl From<LayoutErr> for CollectionAllocErr {
/// * `Layout` queries and calculations in general must be correct. Callers of
/// this trait are allowed to rely on the contracts defined on each method,
/// and implementors must ensure such contracts remain true.
#[unstable(feature = "allocator_api", issue = "32838")]
#[stable(feature = "global_alloc", since = "1.28.0")]
pub unsafe trait GlobalAlloc {
/// Allocate memory as described by the given `layout`.
///
@ -499,6 +499,7 @@ pub unsafe trait GlobalAlloc {
/// Clients wishing to abort computation in response to an
/// allocation error are encouraged to call the [`oom`] function,
/// rather than directly invoking `panic!` or similar.
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn alloc(&self, layout: Layout) -> *mut u8;
/// Deallocate the block of memory at the given `ptr` pointer with the given `layout`.
@ -513,6 +514,7 @@ pub unsafe trait GlobalAlloc {
///
/// * `layout` must be the same layout that was used
/// to allocated that block of memory,
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout);
/// Behaves like `alloc`, but also ensures that the contents
@ -532,6 +534,7 @@ pub unsafe trait GlobalAlloc {
/// Clients wishing to abort computation in response to an
/// allocation error are encouraged to call the [`oom`] function,
/// rather than directly invoking `panic!` or similar.
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let size = layout.size();
let ptr = self.alloc(layout);
@ -589,6 +592,7 @@ pub unsafe trait GlobalAlloc {
/// Clients wishing to abort computation in response to a
/// reallocation error are encouraged to call the [`oom`] function,
/// rather than directly invoking `panic!` or similar.
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let new_layout = Layout::from_size_align_unchecked(new_size, layout.align());
let new_ptr = self.alloc(new_layout);