Skip to content

Commit b07ab1f

Browse files
committed
Migrate users of io::fd_t to io::native::file::fd_t
1 parent 2e0f3f5 commit b07ab1f

File tree

7 files changed

+41
-101
lines changed

7 files changed

+41
-101
lines changed

src/compiletest/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn load_errors(testfile: &Path) -> ~[ExpectedError] {
2626
}
2727

2828
fn parse_expected(line_num: uint, line: ~str) -> ~[ExpectedError] {
29+
let line = line.trim();
2930
let error_tag = ~"//~";
3031
let mut idx;
3132
match line.find_str(error_tag) {

src/libstd/cleanup.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ fn debug_mem() -> bool {
6868
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
6969
pub unsafe fn annihilate() {
7070
use rt::local_heap::local_free;
71-
use io::WriterUtil;
72-
use io;
73-
use libc;
7471
use sys;
7572
use managed;
7673

@@ -126,14 +123,10 @@ pub unsafe fn annihilate() {
126123

127124
if debug_mem() {
128125
// We do logging here w/o allocation.
129-
let dbg = libc::STDERR_FILENO as io::fd_t;
130-
dbg.write_str("annihilator stats:");
131-
dbg.write_str("\n total_boxes: ");
132-
dbg.write_uint(stats.n_total_boxes);
133-
dbg.write_str("\n unique_boxes: ");
134-
dbg.write_uint(stats.n_unique_boxes);
135-
dbg.write_str("\n bytes_freed: ");
136-
dbg.write_uint(stats.n_bytes_freed);
137-
dbg.write_str("\n");
126+
rterrln!("annihilator stats:\n \
127+
total boxes: {}\n \
128+
unique boxes: {}\n \
129+
bytes freed: {}",
130+
stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed);
138131
}
139132
}

src/libstd/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
macro_rules! rterrln (
1515
($($arg:tt)*) => ( {
16-
::rt::util::dumb_println(format!($($arg)*));
16+
format_args!(::rt::util::dumb_println, $($arg)*)
1717
} )
1818
)
1919

src/libstd/rt/borrowck.rs

Lines changed: 6 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99
// except according to those terms.
1010

1111
use cell::Cell;
12-
use c_str::ToCStr;
13-
use cast::transmute;
14-
use io::{Writer, WriterUtil};
15-
use io;
16-
use libc::{c_char, size_t, STDERR_FILENO};
12+
use c_str::{ToCStr, CString};
13+
use libc::{c_char, size_t};
1714
use option::{Option, None, Some};
1815
use ptr::RawPtr;
1916
use rt::env;
@@ -113,51 +110,10 @@ unsafe fn debug_borrow<T,P:RawPtr<T>>(tag: &'static str,
113110
new_bits: uint,
114111
filename: *c_char,
115112
line: size_t) {
116-
let dbg = STDERR_FILENO as io::fd_t;
117-
dbg.write_str(tag);
118-
dbg.write_hex(p.to_uint());
119-
dbg.write_str(" ");
120-
dbg.write_hex(old_bits);
121-
dbg.write_str(" ");
122-
dbg.write_hex(new_bits);
123-
dbg.write_str(" ");
124-
dbg.write_cstr(filename);
125-
dbg.write_str(":");
126-
dbg.write_hex(line as uint);
127-
dbg.write_str("\n");
128-
}
129-
}
130-
131-
trait DebugPrints {
132-
fn write_hex(&self, val: uint);
133-
unsafe fn write_cstr(&self, str: *c_char);
134-
}
135-
136-
impl DebugPrints for io::fd_t {
137-
fn write_hex(&self, mut i: uint) {
138-
let letters = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
139-
'9', 'a', 'b', 'c', 'd', 'e', 'f'];
140-
static UINT_NIBBLES: uint = ::uint::bytes << 1;
141-
let mut buffer = [0_u8, ..UINT_NIBBLES+1];
142-
let mut c = UINT_NIBBLES;
143-
while c > 0 {
144-
c -= 1;
145-
buffer[c] = letters[i & 0xF] as u8;
146-
i >>= 4;
147-
}
148-
self.write(buffer.slice(0, UINT_NIBBLES));
149-
}
150-
151-
unsafe fn write_cstr(&self, p: *c_char) {
152-
#[fixed_stack_segment]; #[inline(never)];
153-
use libc::strlen;
154-
use vec;
155-
156-
let len = strlen(p);
157-
let p: *u8 = transmute(p);
158-
do vec::raw::buf_as_slice(p, len as uint) |s| {
159-
self.write(s);
160-
}
113+
let filename = CString::new(filename, false);
114+
rterrln!("{}{:#x} {:x} {:x} {}:{}",
115+
tag, p.to_uint(), old_bits, new_bits,
116+
filename.as_str().unwrap(), line);
161117
}
162118
}
163119

src/libstd/rt/io/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ pub mod buffered;
313313
pub mod native {
314314
/// Posix file I/O
315315
pub mod file;
316-
/// # XXX - implement this
317-
pub mod stdio { }
316+
/// Process spawning and child management
317+
pub mod process;
318+
/// Posix stdio
319+
pub mod stdio;
320+
318321
/// Sockets
319322
/// # XXX - implement this
320323
pub mod net {

src/libstd/rt/logging.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ use fmt;
1212
use from_str::from_str;
1313
use libc::exit;
1414
use option::{Some, None, Option};
15-
use rt;
16-
use rt::util::dumb_println;
1715
use rt::crate_map::{ModEntry, CrateMap, iter_crate_map, get_crate_map};
1816
use str::StrSlice;
1917
use u32;
@@ -88,16 +86,16 @@ fn parse_logging_spec(spec: ~str) -> ~[LogDirective]{
8886
log_level = num;
8987
},
9088
_ => {
91-
dumb_println(format!("warning: invalid logging spec \
92-
'{}', ignoring it", parts[1]));
93-
continue;
89+
rterrln!("warning: invalid logging spec '{}', \
90+
ignoring it", parts[1]);
91+
continue
9492
}
9593
}
9694
},
9795
_ => {
98-
dumb_println(format!("warning: invalid logging spec '{}',\
99-
ignoring it", s));
100-
continue;
96+
rterrln!("warning: invalid logging spec '{}', \
97+
ignoring it", s);
98+
continue
10199
}
102100
}
103101
let dir = LogDirective {name: name, level: log_level};
@@ -141,9 +139,9 @@ fn update_log_settings(crate_map: &CrateMap, settings: ~str) {
141139
let mut dirs = ~[];
142140
if settings.len() > 0 {
143141
if settings == ~"::help" || settings == ~"?" {
144-
dumb_println("\nCrate log map:\n");
142+
rterrln!("\nCrate log map:\n");
145143
do iter_crate_map(crate_map) |entry| {
146-
dumb_println(" "+entry.name);
144+
rterrln!(" {}", entry.name);
147145
}
148146
unsafe { exit(1); }
149147
}
@@ -157,12 +155,10 @@ fn update_log_settings(crate_map: &CrateMap, settings: ~str) {
157155
}
158156

159157
if n_matches < (dirs.len() as u32) {
160-
dumb_println(format!("warning: got {} RUST_LOG specs but only matched\n\
161-
{} of them. You may have mistyped a RUST_LOG \
162-
spec. \n\
163-
Use RUST_LOG=::help to see the list of crates \
164-
and modules.\n",
165-
dirs.len(), n_matches));
158+
rterrln!("warning: got {} RUST_LOG specs but only matched\n\
159+
{} of them. You may have mistyped a RUST_LOG spec. \n\
160+
Use RUST_LOG=::help to see the list of crates and modules.\n",
161+
dirs.len(), n_matches);
166162
}
167163
}
168164

@@ -174,24 +170,13 @@ pub struct StdErrLogger;
174170

175171
impl Logger for StdErrLogger {
176172
fn log(&mut self, args: &fmt::Arguments) {
177-
fmt::writeln(self as &mut rt::io::Writer, args);
173+
// FIXME(#6846): this should not call the blocking version of println,
174+
// or at least the default loggers for tasks shouldn't do
175+
// that
176+
::rt::util::dumb_println(args);
178177
}
179178
}
180179

181-
impl rt::io::Writer for StdErrLogger {
182-
fn write(&mut self, buf: &[u8]) {
183-
// Nothing like swapping between I/O implementations! In theory this
184-
// could use the libuv bindings for writing to file descriptors, but
185-
// that may not necessarily be desirable because logging should work
186-
// outside of the uv loop. (modify with caution)
187-
use io::Writer;
188-
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
189-
dbg.write(buf);
190-
}
191-
192-
fn flush(&mut self) {}
193-
}
194-
195180
/// Configure logging by traversing the crate map and setting the
196181
/// per-module global logging flags based on the logging spec
197182
pub fn init() {
@@ -212,7 +197,7 @@ pub fn init() {
212197
_ => {
213198
match log_spec {
214199
Some(_) => {
215-
dumb_println("warning: RUST_LOG set, but no crate map found.");
200+
rterrln!("warning: RUST_LOG set, but no crate map found.");
216201
},
217202
None => {}
218203
}

src/libstd/rt/util.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
use container::Container;
12+
use fmt;
1213
use from_str::FromStr;
1314
use libc;
1415
use option::{Some, None, Option};
@@ -74,10 +75,11 @@ pub fn default_sched_threads() -> uint {
7475
}
7576
}
7677

77-
pub fn dumb_println(s: &str) {
78-
use io::WriterUtil;
79-
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
80-
dbg.write_str(s + "\n");
78+
pub fn dumb_println(args: &fmt::Arguments) {
79+
use rt::io::native::stdio::stderr;
80+
use rt::io::Writer;
81+
let mut out = stderr();
82+
fmt::writeln(&mut out as &mut Writer, args);
8183
}
8284

8385
pub fn abort(msg: &str) -> ! {

0 commit comments

Comments
 (0)