Skip to content

Commit 03a8e59

Browse files
committed
Merge remote-tracking branch 'brson/io' into incoming
2 parents 2d28d64 + 018dfaf commit 03a8e59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3003
-1156
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: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,25 @@ pub mod win32 {
147147

148148
/*
149149
Accessing environment variables is not generally threadsafe.
150-
This uses a per-runtime lock to serialize access.
151-
FIXME #4726: It would probably be appropriate to make this a real global
150+
Serialize access through a global lock.
152151
*/
153152
fn with_env_lock<T>(f: &fn() -> T) -> T {
154-
use unstable::global::global_data_clone_create;
155-
use unstable::sync::{Exclusive, exclusive};
156-
157-
struct SharedValue(());
158-
type ValueMutex = Exclusive<SharedValue>;
159-
fn key(_: ValueMutex) { }
153+
use unstable::finally::Finally;
160154

161155
unsafe {
162-
let lock: ValueMutex = global_data_clone_create(key, || {
163-
~exclusive(SharedValue(()))
164-
});
156+
return do (|| {
157+
rust_take_env_lock();
158+
f()
159+
}).finally {
160+
rust_drop_env_lock();
161+
};
162+
}
165163

166-
lock.with_imm(|_| f() )
164+
extern {
165+
#[fast_ffi]
166+
fn rust_take_env_lock();
167+
#[fast_ffi]
168+
fn rust_drop_env_lock();
167169
}
168170
}
169171

@@ -749,7 +751,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
749751
use os::win32::{
750752
as_utf16_p
751753
};
752-
use unstable::exchange_alloc::{malloc_raw, free_raw};
754+
use rt::global_heap::{malloc_raw, free_raw};
753755
#[nolink]
754756
extern {
755757
unsafe fn rust_list_dir_wfd_size() -> libc::size_t;

src/libcore/rt/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub impl Context {
8484
}
8585

8686
extern {
87+
#[rust_stack]
8788
fn swap_registers(out_regs: *mut Registers, in_regs: *Registers);
8889
}
8990

@@ -111,9 +112,9 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
111112
let sp = align_down(sp);
112113
let sp = mut_offset(sp, -4);
113114

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

118119
regs.esp = sp as u32;
119120
regs.eip = fptr as u32;
@@ -195,7 +196,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
195196

196197
fn align_down(sp: *mut uint) -> *mut uint {
197198
unsafe {
198-
let sp = transmute::<*mut uint, uint>(sp);
199+
let sp: uint = transmute(sp);
199200
let sp = sp & !(16 - 1);
200201
transmute::<uint, *mut uint>(sp)
201202
}

src/libcore/unstable/exchange_alloc.rs renamed to src/libcore/rt/global_heap.rs

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

1111
use sys::{TypeDesc, size_of};
12-
use libc::{c_void, size_t};
12+
use libc::{c_void, size_t, uintptr_t};
1313
use c_malloc = libc::malloc;
1414
use c_free = libc::free;
1515
use managed::raw::{BoxHeaderRepr, BoxRepr};
@@ -34,7 +34,7 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
3434
box.header.prev = null();
3535
box.header.next = null();
3636

37-
let exchange_count = &mut *rust_get_exchange_count_ptr();
37+
let exchange_count = &mut *exchange_count_ptr();
3838
atomic_xadd(exchange_count, 1);
3939

4040
return transmute(box);
@@ -52,7 +52,7 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
5252
}
5353

5454
pub unsafe fn free(ptr: *c_void) {
55-
let exchange_count = &mut *rust_get_exchange_count_ptr();
55+
let exchange_count = &mut *exchange_count_ptr();
5656
atomic_xsub(exchange_count, 1);
5757

5858
assert!(ptr.is_not_null());
@@ -77,7 +77,11 @@ fn align_to(size: uint, align: uint) -> uint {
7777
(size + align - 1) & !(align - 1)
7878
}
7979

80+
fn exchange_count_ptr() -> *mut int {
81+
// XXX: Need mutable globals
82+
unsafe { transmute(&rust_exchange_count) }
83+
}
84+
8085
extern {
81-
#[rust_stack]
82-
fn rust_get_exchange_count_ptr() -> *mut int;
86+
static rust_exchange_count: uintptr_t;
8387
}

0 commit comments

Comments
 (0)