std: Handle prints with literally no context
Printing is an incredibly useful debugging utility, and it's not much help if your debugging prints just trigger an obscure abort when you need them most. In order to handle this case, forcibly fall back to a libc::write implementation of printing whenever a local task is not available. Note that this is *not* a 1:1 fallback. All 1:1 rust tasks will still have a local Task that it can go through (and stdio will be created through the local IO factory), this is only a fallback for "no context" rust code (such as that setting up the context).
This commit is contained in:
@@ -132,7 +132,17 @@ fn with_task_stdout(f: |&mut Writer|) {
|
||||
}
|
||||
|
||||
None => {
|
||||
let mut io = stdout();
|
||||
struct Stdout;
|
||||
impl Writer for Stdout {
|
||||
fn write(&mut self, data: &[u8]) {
|
||||
unsafe {
|
||||
libc::write(libc::STDOUT_FILENO,
|
||||
vec::raw::to_ptr(data) as *libc::c_void,
|
||||
data.len() as libc::size_t);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut io = Stdout;
|
||||
f(&mut io as &mut Writer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user