Skip to content

Commit

Permalink
More alloc docs tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jun 11, 2018
1 parent 9dcb64f commit 7f0d54d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/liballoc/alloc.rs
Expand Up @@ -184,8 +184,10 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
///
/// The default behavior of this function is to print a message to standard error
/// and abort the process.
/// It can be replaced with [`std::alloc::set_oom_hook`]
/// and [`std::alloc::take_oom_hook`].
/// It can be replaced with [`set_oom_hook`] and [`take_oom_hook`].
///
/// [`set_oom_hook`]: ../../std/alloc/fn.set_oom_hook.html
/// [`take_oom_hook`]: ../../std/alloc/fn.take_oom_hook.html
#[stable(feature = "global_alloc", since = "1.28.0")]
#[rustc_allocator_nounwind]
pub fn oom(layout: Layout) -> ! {
Expand Down
24 changes: 23 additions & 1 deletion src/libcore/alloc.rs
Expand Up @@ -494,6 +494,8 @@ 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn alloc(&self, layout: Layout) -> *mut u8;

Expand Down Expand Up @@ -529,6 +531,8 @@ 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
#[stable(feature = "global_alloc", since = "1.28.0")]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let size = layout.size();
Expand Down Expand Up @@ -587,6 +591,8 @@ 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
#[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());
Expand Down Expand Up @@ -727,8 +733,10 @@ pub unsafe trait Alloc {
/// library that aborts on memory exhaustion.)
///
/// Clients wishing to abort computation in response to an
/// allocation error are encouraged to call the `oom` function,
/// allocation error are encouraged to call the [`oom`] function,
/// rather than directly invoking `panic!` or similar.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr>;

/// Deallocate the memory referenced by `ptr`.
Expand Down Expand Up @@ -837,6 +845,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn realloc(&mut self,
ptr: NonNull<u8>,
layout: Layout,
Expand Down Expand Up @@ -881,6 +891,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
let size = layout.size();
let p = self.alloc(layout);
Expand All @@ -907,6 +919,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn alloc_excess(&mut self, layout: Layout) -> Result<Excess, AllocErr> {
let usable_size = self.usable_size(&layout);
self.alloc(layout).map(|p| Excess(p, usable_size.1))
Expand All @@ -929,6 +943,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn realloc_excess(&mut self,
ptr: NonNull<u8>,
layout: Layout,
Expand Down Expand Up @@ -1076,6 +1092,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
fn alloc_one<T>(&mut self) -> Result<NonNull<T>, AllocErr>
where Self: Sized
{
Expand Down Expand Up @@ -1143,6 +1161,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
fn alloc_array<T>(&mut self, n: usize) -> Result<NonNull<T>, AllocErr>
where Self: Sized
{
Expand Down Expand Up @@ -1188,6 +1208,8 @@ pub unsafe trait Alloc {
/// 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.
///
/// [`oom`]: ../../alloc/alloc/fn.oom.html
unsafe fn realloc_array<T>(&mut self,
ptr: NonNull<T>,
n_old: usize,
Expand Down

0 comments on commit 7f0d54d

Please sign in to comment.