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