Skip to content

Commit

Permalink
auto merge of #9803 : alexcrichton/rust/less-pub2, r=brson
Browse files Browse the repository at this point in the history
This change was waiting for privacy to get sorted out, which should be true now
that #8215 has landed.

Closes #4427
  • Loading branch information
bors committed Oct 11, 2013
2 parents 93a08f4 + 8b4423b commit ed37b00
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ fn get_concurrency() -> uint {
}
}
None => {
rt::util::default_sched_threads()
rt::default_sched_threads()
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/libstd/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ pub unsafe fn annihilate() {

if debug_mem() {
// We do logging here w/o allocation.
rterrln!("annihilator stats:\n \
total boxes: {}\n \
unique boxes: {}\n \
bytes freed: {}",
stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed);
debug2!("annihilator stats:\n \
total boxes: {}\n \
unique boxes: {}\n \
bytes freed: {}",
stats.n_total_boxes, stats.n_unique_boxes, stats.n_bytes_freed);
}
}
2 changes: 1 addition & 1 deletion src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ pub fn last_os_error() -> ~str {
*/
pub fn set_exit_status(code: int) {
use rt;
rt::util::set_exit_status(code);
rt::set_exit_status(code);
}

unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/rt/borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use option::{Option, None, Some};
use ptr::RawPtr;
use rt::env;
use rt::local::Local;
use rt::task;
use rt::task::Task;
use str::{OwnedStr, StrSlice};
use str;
use sys;
use uint;
use unstable::raw;
use vec::ImmutableVector;
Expand Down Expand Up @@ -64,7 +64,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) {
None => { // not recording borrows
let msg = "borrowed";
do msg.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line);
task::begin_unwind(msg_p, file, line);
}
}
Some(borrow_list) => { // recording borrows
Expand All @@ -80,7 +80,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) {
}
}
do msg.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line)
task::begin_unwind(msg_p, file, line)
}
}
}
Expand Down Expand Up @@ -179,7 +179,7 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
if br.box != a || br.file != file || br.line != line {
let err = format!("wrong borrow found, br={:?}", br);
do err.with_c_str |msg_p| {
sys::begin_unwind_(msg_p, file, line)
task::begin_unwind(msg_p, file, line)
}
}
borrow_list
Expand Down
11 changes: 11 additions & 0 deletions src/libstd/rt/local_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ impl Drop for LocalHeap {
}
}

pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char {
// XXX: Unsafe borrow for speed. Lame.
let task: Option<*mut Task> = Local::try_unsafe_borrow();
match task {
Some(task) => {
(*task).heap.alloc(td as *libc::c_void, size as uint) as *libc::c_char
}
None => rtabort!("local malloc outside of task")
}
}

// A little compatibility function
pub unsafe fn local_free(ptr: *libc::c_char) {
// XXX: Unsafe borrow for speed. Lame.
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/local_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,5 @@ pub fn maybe_tls_key() -> Option<tls::Key> {
#[inline]
#[cfg(test)]
pub fn maybe_tls_key() -> Option<tls::Key> {
unsafe { ::cast::transmute(::realstd::rt::local_ptr::maybe_tls_key()) }
unsafe { ::cast::transmute(::realstd::rt::shouldnt_be_public::maybe_tls_key()) }
}
8 changes: 6 additions & 2 deletions src/libstd/macros.rs → src/libstd/rt/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

macro_rules! rterrln (
($($arg:tt)*) => ( {
Expand Down Expand Up @@ -37,7 +41,7 @@ macro_rules! rtassert (
)


macro_rules! rtabort(
macro_rules! rtabort (
($($msg:tt)*) => ( {
::rt::util::abort(format!($($msg)*));
} )
Expand Down
23 changes: 17 additions & 6 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ use vec::{OwnedVector, MutableVector, ImmutableVector};
use self::thread::Thread;
use self::work_queue::WorkQueue;

// the os module needs to reach into this helper, so allow general access
// through this reexport.
pub use self::util::set_exit_status;

// this is somewhat useful when a program wants to spawn a "reasonable" number
// of workers based on the constraints of the system that it's running on.
// Perhaps this shouldn't be a `pub use` though and there should be another
// method...
pub use self::util::default_sched_threads;

// XXX: these probably shouldn't be public...
#[doc(hidden)]
pub mod shouldnt_be_public {
Expand All @@ -86,8 +96,12 @@ pub mod shouldnt_be_public {
pub use super::select::SelectInner;
pub use super::rtio::EventLoop;
pub use super::select::{SelectInner, SelectPortInner};
pub use super::local_ptr::maybe_tls_key;
}

// Internal macros used by the runtime.
mod macros;

/// The global (exchange) heap.
pub mod global_heap;

Expand Down Expand Up @@ -158,17 +172,14 @@ pub mod comm;

mod select;

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

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

// FIXME #5248 shouldn't be pub
/// Just stuff
pub mod util;
mod util;

// Global command line argument storage
pub mod args;
Expand Down
44 changes: 43 additions & 1 deletion src/libstd/rt/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use borrow;
use cast::transmute;
use cleanup;
use local_data;
use libc::{c_void, uintptr_t};
use libc::{c_void, uintptr_t, c_char, size_t};
use prelude::*;
use option::{Option, Some, None};
use rt::borrowck;
Expand Down Expand Up @@ -465,6 +465,48 @@ impl Unwinder {
}
}

/// This is the entry point of unwinding for things like lang items and such.
/// The arguments are normally generated by the compiler.
pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! {
use rt::in_green_task_context;
use rt::task::Task;
use rt::local::Local;
use rt::logging::Logger;
use str::Str;
use c_str::CString;

unsafe {
let msg = CString::new(msg, false);
let file = CString::new(file, false);
let msg = match msg.as_str() {
Some(s) => s, None => rtabort!("message wasn't utf8?")
};
let file = match file.as_str() {
Some(s) => s, None => rtabort!("message wasn't utf8?")
};

if in_green_task_context() {
// Be careful not to allocate in this block, if we're failing we may
// have been failing due to a lack of memory in the first place...
do Local::borrow |task: &mut Task| {
let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
format_args!(|args| { task.logger.log(args) },
"task '{}' failed at '{}', {}:{}",
n, msg, file, line);
}
} else {
rterrln!("failed in non-task context at '{}', {}:{}",
msg, file, line as int);
}

let task: *mut Task = Local::unsafe_borrow();
if (*task).unwinder.unwinding {
rtabort!("unwinding again");
}
(*task).unwinder.begin_unwind();
}
}

#[cfg(test)]
mod test {
use rt::test::*;
Expand Down
26 changes: 10 additions & 16 deletions src/libstd/rt/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use option::{Some, None, Option};
use os;
use str::StrSlice;
use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};

#[cfg(target_os="macos")]
use unstable::running_on_valgrind;

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

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

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

/// Get's the number of scheduler threads requested by the environment
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ pub mod linkhack {
}
}

// Internal macros
mod macros;

/* The Prelude. */

pub mod prelude;
Expand Down
42 changes: 4 additions & 38 deletions src/libstd/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

use c_str::ToCStr;
use cast;
use libc::size_t;
use libc;
use libc::{c_char, size_t};
use repr;
use rt::task;
use str;
use unstable::intrinsics;

Expand Down Expand Up @@ -109,7 +110,7 @@ impl FailWithCause for ~str {
fn fail_with(cause: ~str, file: &'static str, line: uint) -> ! {
do cause.with_c_str |msg_buf| {
do file.with_c_str |file_buf| {
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
task::begin_unwind(msg_buf, file_buf, line as libc::size_t)
}
}
}
Expand All @@ -119,47 +120,12 @@ impl FailWithCause for &'static str {
fn fail_with(cause: &'static str, file: &'static str, line: uint) -> ! {
do cause.with_c_str |msg_buf| {
do file.with_c_str |file_buf| {
begin_unwind_(msg_buf, file_buf, line as libc::size_t)
task::begin_unwind(msg_buf, file_buf, line as libc::size_t)
}
}
}
}

// FIXME #4427: Temporary until rt::rt_fail_ goes away
pub fn begin_unwind_(msg: *c_char, file: *c_char, line: size_t) -> ! {
use rt::in_green_task_context;
use rt::task::Task;
use rt::local::Local;
use rt::logging::Logger;
use str::Str;

unsafe {
// XXX: Bad re-allocations. fail2! needs some refactoring
let msg = str::raw::from_c_str(msg);
let file = str::raw::from_c_str(file);

if in_green_task_context() {
// Be careful not to allocate in this block, if we're failing we may
// have been failing due to a lack of memory in the first place...
do Local::borrow |task: &mut Task| {
let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>");
format_args!(|args| { task.logger.log(args) },
"task '{}' failed at '{}', {}:{}",
n, msg.as_slice(), file.as_slice(), line);
}
} else {
rterrln!("failed in non-task context at '{}', {}:{}",
msg, file, line as int);
}

let task: *mut Task = Local::unsafe_borrow();
if (*task).unwinder.unwinding {
rtabort!("unwinding again");
}
(*task).unwinder.begin_unwind();
}
}

#[cfg(test)]
mod tests {
use cast;
Expand Down
Loading

0 comments on commit ed37b00

Please sign in to comment.