Refactor stderr_prints_nothing into a more modular function
This commit is contained in:
parent
367e783e6f
commit
030b1ed7f7
7 changed files with 28 additions and 29 deletions
|
@ -29,7 +29,7 @@ use intrinsics;
|
|||
use mem;
|
||||
use ptr;
|
||||
use raw;
|
||||
use sys::stdio::{Stderr, stderr_prints_nothing};
|
||||
use sys::stdio::panic_output;
|
||||
use sys_common::rwlock::RWLock;
|
||||
use sys_common::thread_info;
|
||||
use sys_common::util;
|
||||
|
@ -193,7 +193,6 @@ fn default_hook(info: &PanicInfo) {
|
|||
None => "Box<Any>",
|
||||
}
|
||||
};
|
||||
let mut err = Stderr::new().ok();
|
||||
let thread = thread_info::current_thread();
|
||||
let name = thread.as_ref().and_then(|t| t.name()).unwrap_or("<unnamed>");
|
||||
|
||||
|
@ -215,17 +214,14 @@ fn default_hook(info: &PanicInfo) {
|
|||
}
|
||||
};
|
||||
|
||||
let prev = LOCAL_STDERR.with(|s| s.borrow_mut().take());
|
||||
match (prev, err.as_mut()) {
|
||||
(Some(mut stderr), _) => {
|
||||
write(&mut *stderr);
|
||||
let mut s = Some(stderr);
|
||||
LOCAL_STDERR.with(|slot| {
|
||||
*slot.borrow_mut() = s.take();
|
||||
});
|
||||
}
|
||||
(None, Some(ref mut err)) => { write(err) }
|
||||
_ => {}
|
||||
if let Some(mut local) = LOCAL_STDERR.with(|s| s.borrow_mut().take()) {
|
||||
write(&mut *local);
|
||||
let mut s = Some(local);
|
||||
LOCAL_STDERR.with(|slot| {
|
||||
*slot.borrow_mut() = s.take();
|
||||
});
|
||||
} else if let Some(mut out) = panic_output() {
|
||||
write(&mut out);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -485,7 +481,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp,
|
|||
// Some platforms know that printing to stderr won't ever actually
|
||||
// print anything, and if that's the case we can skip the default
|
||||
// hook.
|
||||
Hook::Default if stderr_prints_nothing() => {}
|
||||
Hook::Default if panic_output().is_none() => {}
|
||||
Hook::Default => {
|
||||
info.set_payload(payload.get());
|
||||
default_hook(&info);
|
||||
|
@ -494,7 +490,7 @@ fn rust_panic_with_hook(payload: &mut dyn BoxMeUp,
|
|||
info.set_payload(payload.get());
|
||||
(*ptr)(&info);
|
||||
}
|
||||
}
|
||||
};
|
||||
HOOK_LOCK.read_unlock();
|
||||
}
|
||||
|
||||
|
|
|
@ -78,6 +78,6 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
|||
|
||||
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn stderr_prints_nothing() -> bool {
|
||||
false
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
}
|
||||
|
|
|
@ -76,6 +76,6 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
|||
|
||||
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn stderr_prints_nothing() -> bool {
|
||||
false
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
}
|
||||
|
|
|
@ -76,6 +76,6 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
|||
|
||||
pub const STDIN_BUF_SIZE: usize = ::sys_common::io::DEFAULT_BUF_SIZE;
|
||||
|
||||
pub fn stderr_prints_nothing() -> bool {
|
||||
false
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
}
|
||||
|
|
|
@ -70,6 +70,10 @@ pub fn is_ebadf(_err: &io::Error) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
pub fn stderr_prints_nothing() -> bool {
|
||||
!cfg!(feature = "wasm_syscall")
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
if cfg!(feature = "wasm_syscall") {
|
||||
Stderr::new().ok()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
|
@ -228,6 +228,6 @@ pub fn is_ebadf(err: &io::Error) -> bool {
|
|||
// been seen to be acceptable.
|
||||
pub const STDIN_BUF_SIZE: usize = 8 * 1024;
|
||||
|
||||
pub fn stderr_prints_nothing() -> bool {
|
||||
false
|
||||
pub fn panic_output() -> Option<impl io::Write> {
|
||||
Stderr::new().ok()
|
||||
}
|
||||
|
|
|
@ -10,14 +10,13 @@
|
|||
|
||||
use fmt;
|
||||
use io::prelude::*;
|
||||
use sys::stdio::{Stderr, stderr_prints_nothing};
|
||||
use sys::stdio::panic_output;
|
||||
use thread;
|
||||
|
||||
pub fn dumb_print(args: fmt::Arguments) {
|
||||
if stderr_prints_nothing() {
|
||||
return
|
||||
if let Some(mut out) = panic_output() {
|
||||
let _ = out.write_fmt(args);
|
||||
}
|
||||
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
|
||||
}
|
||||
|
||||
// Other platforms should use the appropriate platform-specific mechanism for
|
||||
|
|
Loading…
Reference in a new issue