Skip to content

Commit ed37b00

Browse files
committed
auto merge of #9803 : alexcrichton/rust/less-pub2, r=brson
This change was waiting for privacy to get sorted out, which should be true now that #8215 has landed. Closes #4427
2 parents 93a08f4 + 8b4423b commit ed37b00

File tree

14 files changed

+114
-99
lines changed

14 files changed

+114
-99
lines changed

src/libextra/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ fn get_concurrency() -> uint {
739739
}
740740
}
741741
None => {
742-
rt::util::default_sched_threads()
742+
rt::default_sched_threads()
743743
}
744744
}
745745
}

src/libstd/cleanup.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ pub unsafe fn annihilate() {
123123

124124
if debug_mem() {
125125
// We do logging here w/o allocation.
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);
126+
debug2!("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);
131131
}
132132
}

src/libstd/os.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ pub fn last_os_error() -> ~str {
11851185
*/
11861186
pub fn set_exit_status(code: int) {
11871187
use rt;
1188-
rt::util::set_exit_status(code);
1188+
rt::set_exit_status(code);
11891189
}
11901190

11911191
unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {

src/libstd/rt/borrowck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ use option::{Option, None, Some};
1515
use ptr::RawPtr;
1616
use rt::env;
1717
use rt::local::Local;
18+
use rt::task;
1819
use rt::task::Task;
1920
use str::{OwnedStr, StrSlice};
2021
use str;
21-
use sys;
2222
use uint;
2323
use unstable::raw;
2424
use vec::ImmutableVector;
@@ -64,7 +64,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) {
6464
None => { // not recording borrows
6565
let msg = "borrowed";
6666
do msg.with_c_str |msg_p| {
67-
sys::begin_unwind_(msg_p, file, line);
67+
task::begin_unwind(msg_p, file, line);
6868
}
6969
}
7070
Some(borrow_list) => { // recording borrows
@@ -80,7 +80,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) {
8080
}
8181
}
8282
do msg.with_c_str |msg_p| {
83-
sys::begin_unwind_(msg_p, file, line)
83+
task::begin_unwind(msg_p, file, line)
8484
}
8585
}
8686
}
@@ -179,7 +179,7 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
179179
if br.box != a || br.file != file || br.line != line {
180180
let err = format!("wrong borrow found, br={:?}", br);
181181
do err.with_c_str |msg_p| {
182-
sys::begin_unwind_(msg_p, file, line)
182+
task::begin_unwind(msg_p, file, line)
183183
}
184184
}
185185
borrow_list

src/libstd/rt/local_heap.rs

+11
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ impl Drop for LocalHeap {
8686
}
8787
}
8888

89+
pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char {
90+
// XXX: Unsafe borrow for speed. Lame.
91+
let task: Option<*mut Task> = Local::try_unsafe_borrow();
92+
match task {
93+
Some(task) => {
94+
(*task).heap.alloc(td as *libc::c_void, size as uint) as *libc::c_char
95+
}
96+
None => rtabort!("local malloc outside of task")
97+
}
98+
}
99+
89100
// A little compatibility function
90101
pub unsafe fn local_free(ptr: *libc::c_char) {
91102
// XXX: Unsafe borrow for speed. Lame.

src/libstd/rt/local_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,5 @@ pub fn maybe_tls_key() -> Option<tls::Key> {
178178
#[inline]
179179
#[cfg(test)]
180180
pub fn maybe_tls_key() -> Option<tls::Key> {
181-
unsafe { ::cast::transmute(::realstd::rt::local_ptr::maybe_tls_key()) }
181+
unsafe { ::cast::transmute(::realstd::rt::shouldnt_be_public::maybe_tls_key()) }
182182
}

src/libstd/macros.rs renamed to src/libstd/rt/macros.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
//! Macros used by the runtime.
12+
//!
13+
//! These macros call functions which are only accessible in the `rt` module, so
14+
//! they aren't defined anywhere outside of the `rt` module.
15+
1116
#[macro_escape];
12-
#[doc(hidden)];
1317

1418
macro_rules! rterrln (
1519
($($arg:tt)*) => ( {
@@ -37,7 +41,7 @@ macro_rules! rtassert (
3741
)
3842

3943

40-
macro_rules! rtabort(
44+
macro_rules! rtabort (
4145
($($msg:tt)*) => ( {
4246
::rt::util::abort(format!($($msg)*));
4347
} )

src/libstd/rt/mod.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ use vec::{OwnedVector, MutableVector, ImmutableVector};
7676
use self::thread::Thread;
7777
use self::work_queue::WorkQueue;
7878

79+
// the os module needs to reach into this helper, so allow general access
80+
// through this reexport.
81+
pub use self::util::set_exit_status;
82+
83+
// this is somewhat useful when a program wants to spawn a "reasonable" number
84+
// of workers based on the constraints of the system that it's running on.
85+
// Perhaps this shouldn't be a `pub use` though and there should be another
86+
// method...
87+
pub use self::util::default_sched_threads;
88+
7989
// XXX: these probably shouldn't be public...
8090
#[doc(hidden)]
8191
pub mod shouldnt_be_public {
@@ -86,8 +96,12 @@ pub mod shouldnt_be_public {
8696
pub use super::select::SelectInner;
8797
pub use super::rtio::EventLoop;
8898
pub use super::select::{SelectInner, SelectPortInner};
99+
pub use super::local_ptr::maybe_tls_key;
89100
}
90101

102+
// Internal macros used by the runtime.
103+
mod macros;
104+
91105
/// The global (exchange) heap.
92106
pub mod global_heap;
93107

@@ -158,17 +172,14 @@ pub mod comm;
158172

159173
mod select;
160174

161-
// FIXME #5248 shouldn't be pub
162175
/// The runtime needs to be able to put a pointer into thread-local storage.
163-
pub mod local_ptr;
176+
mod local_ptr;
164177

165-
// FIXME #5248: The import in `sched` doesn't resolve unless this is pub!
166178
/// Bindings to pthread/windows thread-local storage.
167-
pub mod thread_local_storage;
179+
mod thread_local_storage;
168180

169-
// FIXME #5248 shouldn't be pub
170181
/// Just stuff
171-
pub mod util;
182+
mod util;
172183

173184
// Global command line argument storage
174185
pub mod args;

src/libstd/rt/task.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use borrow;
1717
use cast::transmute;
1818
use cleanup;
1919
use local_data;
20-
use libc::{c_void, uintptr_t};
20+
use libc::{c_void, uintptr_t, c_char, size_t};
2121
use prelude::*;
2222
use option::{Option, Some, None};
2323
use rt::borrowck;
@@ -465,6 +465,48 @@ impl Unwinder {
465465
}
466466
}
467467

468+
/// This is the entry point of unwinding for things like lang items and such.
469+
/// The arguments are normally generated by the compiler.
470+
pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! {
471+
use rt::in_green_task_context;
472+
use rt::task::Task;
473+
use rt::local::Local;
474+
use rt::logging::Logger;
475+
use str::Str;
476+
use c_str::CString;
477+
478+
unsafe {
479+
let msg = CString::new(msg, false);
480+
let file = CString::new(file, false);
481+
let msg = match msg.as_str() {
482+
Some(s) => s, None => rtabort!("message wasn't utf8?")
483+
};
484+
let file = match file.as_str() {
485+
Some(s) => s, None => rtabort!("message wasn't utf8?")
486+
};
487+
488+
if in_green_task_context() {
489+
// Be careful not to allocate in this block, if we're failing we may
490+
// have been failing due to a lack of memory in the first place...
491+
do Local::borrow |task: &mut Task| {
492+
let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
493+
format_args!(|args| { task.logger.log(args) },
494+
"task '{}' failed at '{}', {}:{}",
495+
n, msg, file, line);
496+
}
497+
} else {
498+
rterrln!("failed in non-task context at '{}', {}:{}",
499+
msg, file, line as int);
500+
}
501+
502+
let task: *mut Task = Local::unsafe_borrow();
503+
if (*task).unwinder.unwinding {
504+
rtabort!("unwinding again");
505+
}
506+
(*task).unwinder.begin_unwind();
507+
}
508+
}
509+
468510
#[cfg(test)]
469511
mod test {
470512
use rt::test::*;

src/libstd/rt/util.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ use option::{Some, None, Option};
1616
use os;
1717
use str::StrSlice;
1818
use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
19-
20-
#[cfg(target_os="macos")]
2119
use unstable::running_on_valgrind;
2220

2321
// Indicates whether we should perform expensive sanity checks, including rtassert!
@@ -37,21 +35,17 @@ pub fn num_cpus() -> uint {
3735
}
3836
}
3937

40-
/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors wired into it; this
41-
/// is a hard limit and requires rebuilding valgrind if you want to go beyond it. Normally this is
42-
/// not a problem, but in some tests, we produce a lot of threads casually. Making lots of threads
43-
/// alone might not be a problem _either_, except on OSX, the segments produced for new threads
44-
/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv schedulers fork off
45-
/// a separate thread for polling fsevents on OSX, we get a perfect storm of creating "too many
46-
/// mappings" for valgrind to handle when running certain stress tests in the runtime.
47-
#[cfg(target_os="macos")]
48-
pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
49-
running_on_valgrind()
50-
}
51-
52-
#[cfg(not(target_os="macos"))]
38+
/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors
39+
/// wired into it; this is a hard limit and requires rebuilding valgrind if you
40+
/// want to go beyond it. Normally this is not a problem, but in some tests, we
41+
/// produce a lot of threads casually. Making lots of threads alone might not
42+
/// be a problem _either_, except on OSX, the segments produced for new threads
43+
/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv
44+
/// schedulers fork off a separate thread for polling fsevents on OSX, we get a
45+
/// perfect storm of creating "too many mappings" for valgrind to handle when
46+
/// running certain stress tests in the runtime.
5347
pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
54-
false
48+
(cfg!(target_os="macos")) && running_on_valgrind()
5549
}
5650

5751
/// Get's the number of scheduler threads requested by the environment

src/libstd/std.rs

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ pub mod linkhack {
8888
}
8989
}
9090

91-
// Internal macros
92-
mod macros;
93-
9491
/* The Prelude. */
9592

9693
pub mod prelude;

src/libstd/sys.rs

+4-38
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
use c_str::ToCStr;
1616
use cast;
17+
use libc::size_t;
1718
use libc;
18-
use libc::{c_char, size_t};
1919
use repr;
20+
use rt::task;
2021
use str;
2122
use unstable::intrinsics;
2223

@@ -109,7 +110,7 @@ impl FailWithCause for ~str {
109110
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
110111
do cause.with_c_str |msg_buf| {
111112
do file.with_c_str |file_buf| {
112-
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
113+
task::begin_unwind(msg_buf, file_buf, line as libc::size_t)
113114
}
114115
}
115116
}
@@ -119,47 +120,12 @@ impl FailWithCause for &'static str {
119120
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
120121
do cause.with_c_str |msg_buf| {
121122
do file.with_c_str |file_buf| {
122-
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
123+
task::begin_unwind(msg_buf, file_buf, line as libc::size_t)
123124
}
124125
}
125126
}
126127
}
127128

128-
// FIXME #4427: Temporary until rt::rt_fail_ goes away
129-
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
130-
use rt::in_green_task_context;
131-
use rt::task::Task;
132-
use rt::local::Local;
133-
use rt::logging::Logger;
134-
use str::Str;
135-
136-
unsafe {
137-
// XXX: Bad re-allocations. fail2! needs some refactoring
138-
let msg = str::raw::from_c_str(msg);
139-
let file = str::raw::from_c_str(file);
140-
141-
if in_green_task_context() {
142-
// Be careful not to allocate in this block, if we're failing we may
143-
// have been failing due to a lack of memory in the first place...
144-
do Local::borrow |task: &mut Task| {
145-
let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
146-
format_args!(|args| { task.logger.log(args) },
147-
"task '{}' failed at '{}', {}:{}",
148-
n, msg.as_slice(), file.as_slice(), line);
149-
}
150-
} else {
151-
rterrln!("failed in non-task context at '{}', {}:{}",
152-
msg, file, line as int);
153-
}
154-
155-
let task: *mut Task = Local::unsafe_borrow();
156-
if (*task).unwinder.unwinding {
157-
rtabort!("unwinding again");
158-
}
159-
(*task).unwinder.begin_unwind();
160-
}
161-
}
162-
163129
#[cfg(test)]
164130
mod tests {
165131
use cast;

0 commit comments

Comments
 (0)