Stablize the alloc module without changing stability of its contents.
This commit is contained in:
@@ -10,17 +10,20 @@
|
||||
|
||||
//! Memory allocation APIs
|
||||
|
||||
#![unstable(issue = "32838", feature = "allocator_api")]
|
||||
|
||||
#[doc(inline)] pub use alloc_crate::alloc::{Global, Layout, oom};
|
||||
#[doc(inline)] pub use alloc_crate::alloc::{alloc, alloc_zeroed, dealloc, realloc};
|
||||
#[doc(inline)] pub use alloc_system::System;
|
||||
#[doc(inline)] pub use core::alloc::*;
|
||||
#![stable(feature = "alloc_module", since = "1.28.0")]
|
||||
|
||||
use core::sync::atomic::{AtomicPtr, Ordering};
|
||||
use core::{mem, ptr};
|
||||
use sys_common::util::dumb_print;
|
||||
|
||||
#[stable(feature = "alloc_module", since = "1.28.0")]
|
||||
#[doc(inline)]
|
||||
pub use alloc_crate::alloc::*;
|
||||
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
#[doc(inline)]
|
||||
pub use alloc_system::System;
|
||||
|
||||
static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
|
||||
|
||||
/// Registers a custom OOM hook, replacing any that was previously registered.
|
||||
@@ -34,6 +37,7 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
|
||||
/// about the allocation that failed.
|
||||
///
|
||||
/// The OOM hook is a global resource.
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn set_oom_hook(hook: fn(Layout)) {
|
||||
HOOK.store(hook as *mut (), Ordering::SeqCst);
|
||||
}
|
||||
@@ -43,6 +47,7 @@ pub fn set_oom_hook(hook: fn(Layout)) {
|
||||
/// *See also the function [`set_oom_hook`].*
|
||||
///
|
||||
/// If no custom hook is registered, the default hook will be returned.
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn take_oom_hook() -> fn(Layout) {
|
||||
let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst);
|
||||
if hook.is_null() {
|
||||
@@ -59,6 +64,7 @@ fn default_oom_hook(layout: Layout) {
|
||||
#[cfg(not(test))]
|
||||
#[doc(hidden)]
|
||||
#[lang = "oom"]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub extern fn rust_oom(layout: Layout) -> ! {
|
||||
let hook = HOOK.load(Ordering::SeqCst);
|
||||
let hook: fn(Layout) = if hook.is_null() {
|
||||
@@ -73,6 +79,7 @@ pub extern fn rust_oom(layout: Layout) -> ! {
|
||||
#[cfg(not(test))]
|
||||
#[doc(hidden)]
|
||||
#[allow(unused_attributes)]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub mod __default_lib_allocator {
|
||||
use super::{System, Layout, GlobalAlloc};
|
||||
// for symbol names src/librustc/middle/allocator.rs
|
||||
|
||||
Reference in New Issue
Block a user