mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-27 07:03:45 +00:00
Replace a couple of asserts with rtassert! in rt code
This replaces a couple of panic locations with hard aborts. The panics can't be catched by the user anyway in these locations.
This commit is contained in:
parent
1ad44b23d1
commit
cb14269145
@ -26,38 +26,6 @@ use crate::sys;
|
||||
use crate::sys_common::thread_info;
|
||||
use crate::thread::Thread;
|
||||
|
||||
// One-time runtime initialization.
|
||||
// Runs before `main`.
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
unsafe {
|
||||
sys::init(argc, argv);
|
||||
|
||||
let main_guard = sys::thread::guard::init();
|
||||
// Next, set up the current Thread with the guard information we just
|
||||
// created. Note that this isn't necessary in general for new threads,
|
||||
// but we just do this to name the main thread and to give it correct
|
||||
// info about the stack bounds.
|
||||
let thread = Thread::new(Some(CString::new("main").unwrap()));
|
||||
thread_info::set(main_guard, thread);
|
||||
}
|
||||
}
|
||||
|
||||
// One-time runtime cleanup.
|
||||
// Runs after `main` or at program exit.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub(crate) fn cleanup() {
|
||||
static CLEANUP: Once = Once::new();
|
||||
CLEANUP.call_once(|| unsafe {
|
||||
// Flush stdout and disable buffering.
|
||||
crate::io::cleanup();
|
||||
// SAFETY: Only called once during runtime cleanup.
|
||||
sys::cleanup();
|
||||
});
|
||||
}
|
||||
|
||||
// Prints to the "panic output", depending on the platform this may be:
|
||||
// - the standard error output
|
||||
// - some dedicated platform specific output
|
||||
@ -99,6 +67,38 @@ macro_rules! rtunwrap {
|
||||
};
|
||||
}
|
||||
|
||||
// One-time runtime initialization.
|
||||
// Runs before `main`.
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
unsafe {
|
||||
sys::init(argc, argv);
|
||||
|
||||
let main_guard = sys::thread::guard::init();
|
||||
// Next, set up the current Thread with the guard information we just
|
||||
// created. Note that this isn't necessary in general for new threads,
|
||||
// but we just do this to name the main thread and to give it correct
|
||||
// info about the stack bounds.
|
||||
let thread = Thread::new(Some(rtunwrap!(Ok, CString::new("main"))));
|
||||
thread_info::set(main_guard, thread);
|
||||
}
|
||||
}
|
||||
|
||||
// One-time runtime cleanup.
|
||||
// Runs after `main` or at program exit.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub(crate) fn cleanup() {
|
||||
static CLEANUP: Once = Once::new();
|
||||
CLEANUP.call_once(|| unsafe {
|
||||
// Flush stdout and disable buffering.
|
||||
crate::io::cleanup();
|
||||
// SAFETY: Only called once during runtime cleanup.
|
||||
sys::cleanup();
|
||||
});
|
||||
}
|
||||
|
||||
// To reduce the generated code of the new `lang_start`, this function is doing
|
||||
// the real work.
|
||||
#[cfg(not(test))]
|
||||
|
@ -120,7 +120,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
|
||||
unsafe fn reset_sigpipe() {
|
||||
#[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
|
||||
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
|
||||
rtassert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,6 @@ pub fn stack_guard() -> Option<Guard> {
|
||||
}
|
||||
|
||||
pub fn set(stack_guard: Option<Guard>, thread: Thread) {
|
||||
THREAD_INFO.with(|c| assert!(c.borrow().is_none()));
|
||||
THREAD_INFO.with(|c| rtassert!(c.borrow().is_none()));
|
||||
THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo { stack_guard, thread }));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user