Migrate users of io::fd_t to io::native::file::fd_t
This commit is contained in:
parent
2e0f3f5b51
commit
b07ab1fe4b
@ -26,6 +26,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
|
||||
}
|
||||
|
||||
fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
|
||||
let line = line.trim();
|
||||
let error_tag = ~"//~";
|
||||
let mut idx;
|
||||
match line.find_str(error_tag) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
macro_rules! rterrln (
|
||||
($($arg:tt)*) => ( {
|
||||
::rt::util::dumb_println(format!($($arg)*));
|
||||
format_args!(::rt::util::dumb_println, $($arg)*)
|
||||
} )
|
||||
)
|
||||
|
||||
|
@ -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_slow<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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,8 +313,11 @@
|
||||
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 {
|
||||
|
@ -12,8 +12,6 @@
|
||||
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 trait Logger {
|
||||
|
||||
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 => {}
|
||||
}
|
||||
|
@ -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) -> ! {
|
||||
|
Loading…
Reference in New Issue
Block a user