Skip to content

Commit b04fce6

Browse files
committed
Merge remote-tracking branch 'brson/io-upstream' into incoming
Conflicts: src/libcore/logging.rs src/libcore/rt/local_services.rs src/libcore/rt/uv/mod.rs src/libcore/rt/uv/net.rs src/libcore/rt/uv/uvio.rs src/libcore/unstable.rs
2 parents 043d022 + ee0ce64 commit b04fce6

36 files changed

+1552
-660
lines changed

src/libcore/core.rc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ mod unicode;
205205
#[path = "num/cmath.rs"]
206206
mod cmath;
207207
mod stackwalk;
208+
209+
// XXX: This shouldn't be pub, and it should be reexported under 'unstable'
210+
// but name resolution doesn't work without it being pub.
208211
#[path = "rt/mod.rs"]
209-
mod rt;
212+
pub mod rt;
210213

211214
// A curious inner-module that's not exported that contains the binding
212215
// 'core' so that macro-expanded references to core::error and such

src/libcore/logging.rs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010

1111
//! Logging
1212
13-
pub mod rustrt {
14-
use libc;
15-
16-
pub extern {
17-
unsafe fn rust_log_console_on();
18-
unsafe fn rust_log_console_off();
19-
unsafe fn rust_log_str(level: u32,
20-
string: *libc::c_char,
21-
size: libc::size_t);
22-
}
23-
}
13+
use option::*;
14+
use either::*;
15+
use rt;
16+
use rt::logging::{Logger, StdErrLogger};
17+
use io;
18+
use libc;
19+
use repr;
20+
use vec;
21+
use cast;
22+
use str;
2423

2524
/// Turns on logging to stdout globally
2625
pub fn console_on() {
@@ -55,8 +54,46 @@ pub fn log_type<T>(level: u32, object: &T) {
5554
let bytes = do io::with_bytes_writer |writer| {
5655
repr::write_repr(writer, object);
5756
};
57+
58+
match rt::context() {
59+
rt::OldTaskContext => {
60+
unsafe {
61+
let len = bytes.len() as libc::size_t;
62+
rustrt::rust_log_str(level, cast::transmute(vec::raw::to_ptr(bytes)), len);
63+
}
64+
}
65+
_ => {
66+
// XXX: Bad allocation
67+
let msg = str::from_bytes(bytes);
68+
newsched_log_str(msg);
69+
}
70+
}
71+
}
72+
73+
fn newsched_log_str(msg: ~str) {
5874
unsafe {
59-
let len = bytes.len() as libc::size_t;
60-
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
75+
match rt::local_services::unsafe_try_borrow_local_services() {
76+
Some(local) => {
77+
// Use the available logger
78+
(*local).logger.log(Left(msg));
79+
}
80+
None => {
81+
// There is no logger anywhere, just write to stderr
82+
let mut logger = StdErrLogger;
83+
logger.log(Left(msg));
84+
}
85+
}
86+
}
87+
}
88+
89+
pub mod rustrt {
90+
use libc;
91+
92+
pub extern {
93+
unsafe fn rust_log_console_on();
94+
unsafe fn rust_log_console_off();
95+
unsafe fn rust_log_str(level: u32,
96+
string: *libc::c_char,
97+
size: libc::size_t);
6198
}
6299
}

src/libcore/macros.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,24 @@ macro_rules! rtdebug (
3030
($( $arg:expr),+) => ( $(let _ = $arg)*; )
3131
)
3232

33+
macro_rules! rtassert (
34+
( $arg:expr ) => ( {
35+
if !$arg {
36+
abort!("assertion failed: %s", stringify!($arg));
37+
}
38+
} )
39+
)
40+
3341
macro_rules! abort(
3442
($( $msg:expr),+) => ( {
3543
rtdebug!($($msg),+);
3644

37-
unsafe { ::libc::abort(); }
45+
do_abort();
46+
47+
// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
48+
// which causes spurious 'unnecessary unsafe block' warnings.
49+
fn do_abort() -> ! {
50+
unsafe { ::libc::abort(); }
51+
}
3852
} )
3953
)

src/libcore/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
722722
use os::win32::{
723723
as_utf16_p
724724
};
725-
use unstable::exchange_alloc::{malloc_raw, free_raw};
725+
use rt::global_heap::{malloc_raw, free_raw};
726726
#[nolink]
727727
extern {
728728
unsafe fn rust_list_dir_wfd_size() -> libc::size_t;

src/libcore/rt/context.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
111111
let sp = align_down(sp);
112112
let sp = mut_offset(sp, -4);
113113

114-
unsafe { *sp = arg as uint; }
114+
unsafe { *sp = arg as uint };
115115
let sp = mut_offset(sp, -1);
116-
unsafe { *sp = 0; } // The final return address
116+
unsafe { *sp = 0 }; // The final return address
117117

118118
regs.esp = sp as u32;
119119
regs.eip = fptr as u32;
@@ -195,7 +195,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
195195

196196
fn align_down(sp: *mut uint) -> *mut uint {
197197
unsafe {
198-
let sp = transmute::<*mut uint, uint>(sp);
198+
let sp: uint = transmute(sp);
199199
let sp = sp & !(16 - 1);
200200
transmute::<uint, *mut uint>(sp)
201201
}

src/libcore/rt/io/file.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use prelude::*;
1212
use super::support::PathLike;
13-
use super::{Reader, Writer, Seek, Close};
13+
use super::{Reader, Writer, Seek};
1414
use super::SeekStyle;
1515

1616
/// # XXX
@@ -69,10 +69,6 @@ impl Seek for FileStream {
6969
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }
7070
}
7171

72-
impl Close for FileStream {
73-
fn close(&mut self) { fail!() }
74-
}
75-
7672
#[test]
7773
#[ignore]
7874
fn super_simple_smoke_test_lets_go_read_some_files_and_have_a_good_time() {

src/libcore/rt/io/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Out of scope
238238
* How does I/O relate to the Iterator trait?
239239
* std::base64 filters
240240
* Using conditions is a big unknown since we don't have much experience with them
241+
* Too many uses of OtherIoError
241242
242243
*/
243244

@@ -252,7 +253,9 @@ pub use self::stdio::println;
252253

253254
pub use self::file::FileStream;
254255
pub use self::net::ip::IpAddr;
256+
#[cfg(not(stage0))]
255257
pub use self::net::tcp::TcpListener;
258+
#[cfg(not(stage0))]
256259
pub use self::net::tcp::TcpStream;
257260
pub use self::net::udp::UdpStream;
258261

@@ -266,6 +269,7 @@ pub mod file;
266269

267270
/// Synchronous, non-blocking network I/O.
268271
pub mod net {
272+
#[cfg(not(stage0))]
269273
pub mod tcp;
270274
pub mod udp;
271275
pub mod ip;
@@ -326,12 +330,14 @@ pub struct IoError {
326330

327331
#[deriving(Eq)]
328332
pub enum IoErrorKind {
333+
PreviousIoError,
334+
OtherIoError,
335+
EndOfFile,
329336
FileNotFound,
330-
FilePermission,
337+
PermissionDenied,
331338
ConnectionFailed,
332339
Closed,
333-
OtherIoError,
334-
PreviousIoError
340+
ConnectionRefused,
335341
}
336342

337343
// XXX: Can't put doc comments on macros
@@ -383,16 +389,7 @@ pub trait Writer {
383389
fn flush(&mut self);
384390
}
385391

386-
/// I/O types that may be closed
387-
///
388-
/// Any further operations performed on a closed resource will raise
389-
/// on `io_error`
390-
pub trait Close {
391-
/// Close the I/O resource
392-
fn close(&mut self);
393-
}
394-
395-
pub trait Stream: Reader + Writer + Close { }
392+
pub trait Stream: Reader + Writer { }
396393

397394
pub enum SeekStyle {
398395
/// Seek from the beginning of the stream

src/libcore/rt/io/native/file.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ impl Writer for FileDesc {
4040
fn flush(&mut self) { fail!() }
4141
}
4242

43-
impl Close for FileDesc {
44-
fn close(&mut self) { fail!() }
45-
}
46-
4743
impl Seek for FileDesc {
4844
fn tell(&self) -> u64 { fail!() }
4945

@@ -72,10 +68,6 @@ impl Writer for CFile {
7268
fn flush(&mut self) { fail!() }
7369
}
7470

75-
impl Close for CFile {
76-
fn close(&mut self) { fail!() }
77-
}
78-
7971
impl Seek for CFile {
8072
fn tell(&self) -> u64 { fail!() }
8173
fn seek(&mut self, _pos: i64, _style: SeekStyle) { fail!() }

0 commit comments

Comments
 (0)