diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-06 13:24:50 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-10-10 03:38:51 -0700 |
| commit | b07ab1fe4baa584401fa17a7ba20bea8c97c5043 (patch) | |
| tree | 4badfcd00208c0c9686b678b72c36183f54ca8fb /src/libstd | |
| parent | 2e0f3f5b510112395a40a0cb5bfbb6aac510d808 (diff) | |
| download | rust-b07ab1fe4baa584401fa17a7ba20bea8c97c5043.tar.gz rust-b07ab1fe4baa584401fa17a7ba20bea8c97c5043.zip | |
Migrate users of io::fd_t to io::native::file::fd_t
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/cleanup.rs | 17 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 56 | ||||
| -rw-r--r-- | src/libstd/rt/io/mod.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/logging.rs | 49 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 10 |
6 files changed, 40 insertions, 101 deletions
diff --git a/src/libstd/cleanup.rs b/src/libstd/cleanup.rs index 6b982ec75da..1c9944664ee 100644 --- a/src/libstd/cleanup.rs +++ b/src/libstd/cleanup.rs @@ -68,9 +68,6 @@ fn debug_mem() -> bool { /// Destroys all managed memory (i.e. @ boxes) held by the current task. pub unsafe fn annihilate() { use rt::local_heap::local_free; - use io::WriterUtil; - use io; - use libc; use sys; use managed; @@ -126,14 +123,10 @@ pub unsafe fn annihilate() { if debug_mem() { // We do logging here w/o allocation. - let dbg = libc::STDERR_FILENO as io::fd_t; - dbg.write_str("annihilator stats:"); - dbg.write_str("\n total_boxes: "); - dbg.write_uint(stats.n_total_boxes); - dbg.write_str("\n unique_boxes: "); - dbg.write_uint(stats.n_unique_boxes); - dbg.write_str("\n bytes_freed: "); - dbg.write_uint(stats.n_bytes_freed); - dbg.write_str("\n"); + rterrln!("annihilator stats:\n \ + total boxes: {}\n \ + unique boxes: {}\n \ + bytes freed: {}", + stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed); } } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 0b1475ff380..7fd27ea7ccc 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -13,7 +13,7 @@ macro_rules! rterrln ( ($($arg:tt)*) => ( { - ::rt::util::dumb_println(format!($($arg)*)); + format_args!(::rt::util::dumb_println, $($arg)*) } ) ) diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index d703272420c..6be23a983ab 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -9,11 +9,8 @@ // except according to those terms. use cell::Cell; -use c_str::ToCStr; -use cast::transmute; -use io::{Writer, WriterUtil}; -use io; -use libc::{c_char, size_t, STDERR_FILENO}; +use c_str::{ToCStr, CString}; +use libc::{c_char, size_t}; use option::{Option, None, Some}; use ptr::RawPtr; use rt::env; @@ -113,51 +110,10 @@ unsafe fn debug_borrow<T,P:RawPtr<T>>(tag: &'static str, new_bits: uint, filename: *c_char, line: size_t) { - let dbg = STDERR_FILENO as io::fd_t; - dbg.write_str(tag); - dbg.write_hex(p.to_uint()); - dbg.write_str(" "); - dbg.write_hex(old_bits); - dbg.write_str(" "); - dbg.write_hex(new_bits); - dbg.write_str(" "); - dbg.write_cstr(filename); - dbg.write_str(":"); - dbg.write_hex(line as uint); - dbg.write_str("\n"); - } -} - -trait DebugPrints { - fn write_hex(&self, val: uint); - unsafe fn write_cstr(&self, str: *c_char); -} - -impl DebugPrints for io::fd_t { - fn write_hex(&self, mut i: uint) { - let letters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', - '9', 'a', 'b', 'c', 'd', 'e', 'f']; - static UINT_NIBBLES: uint = ::uint::bytes << 1; - let mut buffer = [0_u8, ..UINT_NIBBLES+1]; - let mut c = UINT_NIBBLES; - while c > 0 { - c -= 1; - buffer[c] = letters[i & 0xF] as u8; - i >>= 4; - } - self.write(buffer.slice(0, UINT_NIBBLES)); - } - - unsafe fn write_cstr(&self, p: *c_char) { - #[fixed_stack_segment]; #[inline(never)]; - use libc::strlen; - use vec; - - let len = strlen(p); - let p: *u8 = transmute(p); - do vec::raw::buf_as_slice(p, len as uint) |s| { - self.write(s); - } + let filename = CString::new(filename, false); + rterrln!("{}{:#x} {:x} {:x} {}:{}", + tag, p.to_uint(), old_bits, new_bits, + filename.as_str().unwrap(), line); } } diff --git a/src/libstd/rt/io/mod.rs b/src/libstd/rt/io/mod.rs index a18f97930fa..d56ad9ce848 100644 --- a/src/libstd/rt/io/mod.rs +++ b/src/libstd/rt/io/mod.rs @@ -313,8 +313,11 @@ pub mod buffered; pub mod native { /// Posix file I/O pub mod file; - /// # XXX - implement this - pub mod stdio { } + /// Process spawning and child management + pub mod process; + /// Posix stdio + pub mod stdio; + /// Sockets /// # XXX - implement this pub mod net { diff --git a/src/libstd/rt/logging.rs b/src/libstd/rt/logging.rs index b08e76921d8..660d1cd4359 100644 --- a/src/libstd/rt/logging.rs +++ b/src/libstd/rt/logging.rs @@ -12,8 +12,6 @@ use fmt; use from_str::from_str; use libc::exit; use option::{Some, None, Option}; -use rt; -use rt::util::dumb_println; use rt::crate_map::{ModEntry, CrateMap, iter_crate_map, get_crate_map}; use str::StrSlice; use u32; @@ -88,16 +86,16 @@ fn parse_logging_spec(spec: ~str) -> ~[LogDirective]{ log_level = num; }, _ => { - dumb_println(format!("warning: invalid logging spec \ - '{}', ignoring it", parts[1])); - continue; + rterrln!("warning: invalid logging spec '{}', \ + ignoring it", parts[1]); + continue } } }, _ => { - dumb_println(format!("warning: invalid logging spec '{}',\ - ignoring it", s)); - continue; + rterrln!("warning: invalid logging spec '{}', \ + ignoring it", s); + continue } } let dir = LogDirective {name: name, level: log_level}; @@ -141,9 +139,9 @@ fn update_log_settings(crate_map: &CrateMap, settings: ~str) { let mut dirs = ~[]; if settings.len() > 0 { if settings == ~"::help" || settings == ~"?" { - dumb_println("\nCrate log map:\n"); + rterrln!("\nCrate log map:\n"); do iter_crate_map(crate_map) |entry| { - dumb_println(" "+entry.name); + rterrln!(" {}", entry.name); } unsafe { exit(1); } } @@ -157,12 +155,10 @@ fn update_log_settings(crate_map: &CrateMap, settings: ~str) { } if n_matches < (dirs.len() as u32) { - dumb_println(format!("warning: got {} RUST_LOG specs but only matched\n\ - {} of them. You may have mistyped a RUST_LOG \ - spec. \n\ - Use RUST_LOG=::help to see the list of crates \ - and modules.\n", - dirs.len(), n_matches)); + rterrln!("warning: got {} RUST_LOG specs but only matched\n\ + {} of them. You may have mistyped a RUST_LOG spec. \n\ + Use RUST_LOG=::help to see the list of crates and modules.\n", + dirs.len(), n_matches); } } @@ -174,24 +170,13 @@ pub struct StdErrLogger; impl Logger for StdErrLogger { fn log(&mut self, args: &fmt::Arguments) { - fmt::writeln(self as &mut rt::io::Writer, args); + // FIXME(#6846): this should not call the blocking version of println, + // or at least the default loggers for tasks shouldn't do + // that + ::rt::util::dumb_println(args); } } -impl rt::io::Writer for StdErrLogger { - fn write(&mut self, buf: &[u8]) { - // Nothing like swapping between I/O implementations! In theory this - // could use the libuv bindings for writing to file descriptors, but - // that may not necessarily be desirable because logging should work - // outside of the uv loop. (modify with caution) - use io::Writer; - let dbg = ::libc::STDERR_FILENO as ::io::fd_t; - dbg.write(buf); - } - - fn flush(&mut self) {} -} - /// Configure logging by traversing the crate map and setting the /// per-module global logging flags based on the logging spec pub fn init() { @@ -212,7 +197,7 @@ pub fn init() { _ => { match log_spec { Some(_) => { - dumb_println("warning: RUST_LOG set, but no crate map found."); + rterrln!("warning: RUST_LOG set, but no crate map found."); }, None => {} } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 68996a3a2a5..727bdb782d2 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -9,6 +9,7 @@ // except according to those terms. use container::Container; +use fmt; use from_str::FromStr; use libc; use option::{Some, None, Option}; @@ -74,10 +75,11 @@ pub fn default_sched_threads() -> uint { } } -pub fn dumb_println(s: &str) { - use io::WriterUtil; - let dbg = ::libc::STDERR_FILENO as ::io::fd_t; - dbg.write_str(s + "\n"); +pub fn dumb_println(args: &fmt::Arguments) { + use rt::io::native::stdio::stderr; + use rt::io::Writer; + let mut out = stderr(); + fmt::writeln(&mut out as &mut Writer, args); } pub fn abort(msg: &str) -> ! { |
