Skip to content

Commit

Permalink
Stablize the GlobalAlloc trait
Browse files Browse the repository at this point in the history
Fixes #49668
  • Loading branch information
SimonSapin committed Jun 11, 2018
1 parent 77606f2 commit bbaff03
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libcore/alloc.rs
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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`.
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bbaff03

Please sign in to comment.