Auto merge of #42727 - alexcrichton:allocators-new, r=eddyb
rustc: Implement the #[global_allocator] attribute This PR is an implementation of [RFC 1974] which specifies a new method of defining a global allocator for a program. This obsoletes the old `#![allocator]` attribute and also removes support for it. [RFC 1974]: https://github.com/rust-lang/rfcs/pull/1974 The new `#[global_allocator]` attribute solves many issues encountered with the `#![allocator]` attribute such as composition and restrictions on the crate graph itself. The compiler now has much more control over the ABI of the allocator and how it's implemented, allowing much more freedom in terms of how this feature is implemented. cc #27389
This commit is contained in:
@@ -59,8 +59,6 @@ pub mod stdio;
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn init() {
|
||||
use alloc::oom;
|
||||
|
||||
// By default, some platforms will send a *signal* when an EPIPE error
|
||||
// would otherwise be delivered. This runtime doesn't install a SIGPIPE
|
||||
// handler, causing it to kill the program, which isn't exactly what we
|
||||
@@ -72,24 +70,6 @@ pub fn init() {
|
||||
reset_sigpipe();
|
||||
}
|
||||
|
||||
oom::set_oom_handler(oom_handler);
|
||||
|
||||
// A nicer handler for out-of-memory situations than the default one. This
|
||||
// one prints a message to stderr before aborting. It is critical that this
|
||||
// code does not allocate any memory since we are in an OOM situation. Any
|
||||
// errors are ignored while printing since there's nothing we can do about
|
||||
// them and we are about to exit anyways.
|
||||
fn oom_handler() -> ! {
|
||||
use intrinsics;
|
||||
let msg = "fatal runtime error: out of memory\n";
|
||||
unsafe {
|
||||
libc::write(libc::STDERR_FILENO,
|
||||
msg.as_ptr() as *const libc::c_void,
|
||||
msg.len());
|
||||
intrinsics::abort();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "nacl", target_os = "emscripten", target_os="fuchsia")))]
|
||||
unsafe fn reset_sigpipe() {
|
||||
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
|
||||
|
||||
@@ -47,24 +47,6 @@ pub mod stdio;
|
||||
|
||||
#[cfg(not(test))]
|
||||
pub fn init() {
|
||||
::alloc::oom::set_oom_handler(oom_handler);
|
||||
|
||||
// See comment in sys/unix/mod.rs
|
||||
fn oom_handler() -> ! {
|
||||
use intrinsics;
|
||||
use ptr;
|
||||
let msg = "fatal runtime error: out of memory\n";
|
||||
unsafe {
|
||||
// WriteFile silently fails if it is passed an invalid handle, so
|
||||
// there is no need to check the result of GetStdHandle.
|
||||
c::WriteFile(c::GetStdHandle(c::STD_ERROR_HANDLE),
|
||||
msg.as_ptr() as c::LPVOID,
|
||||
msg.len() as c::DWORD,
|
||||
ptr::null_mut(),
|
||||
ptr::null_mut());
|
||||
intrinsics::abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn decode_error_kind(errno: i32) -> ErrorKind {
|
||||
|
||||
Reference in New Issue
Block a user