Skip to content

Commit

Permalink
Stablize the GlobalAlloc trait
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed May 31, 2018
1 parent 763b55a commit 83b88f8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libcore/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ impl From<AllocErr> 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 @@ -487,6 +487,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 @@ -501,6 +502,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 @@ -520,6 +522,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 @@ -577,6 +580,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 83b88f8

Please sign in to comment.