Make most of std::rt private

Previously, the entire runtime API surface was publicly exposed, but
that is neither necessary nor desirable. This commit hides most of the
module, using librustrt directly as needed. The arrangement will need to
be revisited when rustrt is pulled into std.

[breaking-change]
This commit is contained in:
Aaron Turon 2014-11-14 16:30:16 -08:00
parent 40c78ab037
commit 6987ad22e4
24 changed files with 64 additions and 81 deletions

View File

@ -666,6 +666,8 @@ pub mod raw {
#[cfg(test)]
mod tests {
extern crate rustrt;
use std::cell::Cell;
use std::default::Default;
use std::mem;
@ -949,9 +951,9 @@ mod tests {
#[test]
fn test_swap_remove_noncopyable() {
// Tests that we don't accidentally run destructors twice.
let mut v = vec![rt::exclusive::Exclusive::new(()),
rt::exclusive::Exclusive::new(()),
rt::exclusive::Exclusive::new(())];
let mut v = vec![rustrt::exclusive::Exclusive::new(()),
rustrt::exclusive::Exclusive::new(()),
rustrt::exclusive::Exclusive::new(())];
let mut _e = v.swap_remove(0);
assert_eq!(v.len(), 2);
_e = v.swap_remove(1);

View File

@ -52,8 +52,10 @@ impl Local<local_ptr::Borrowed<Task>> for Task {
#[cfg(test)]
mod test {
extern crate rustrt;
use std::prelude::*;
use std::rt::thread::Thread;
use rustrt::thread::Thread;
use super::*;
use task::Task;

View File

@ -33,7 +33,7 @@
//! # Example
//!
//! ```rust
//! use std::rt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//! use rustrt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//!
//! // Use a statically initialized mutex
//! static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
@ -108,7 +108,7 @@ impl StaticNativeMutex {
/// # Example
///
/// ```rust
/// use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
/// use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
/// static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
/// unsafe {
/// let _guard = LOCK.lock();
@ -225,7 +225,7 @@ impl NativeMutex {
/// # Example
///
/// ```rust
/// use std::rt::mutex::NativeMutex;
/// use rustrt::mutex::NativeMutex;
/// unsafe {
/// let mut lock = NativeMutex::new();
///
@ -649,11 +649,13 @@ mod imp {
#[cfg(test)]
mod test {
extern crate rustrt;
use std::prelude::*;
use std::mem::drop;
use super::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use std::rt::thread::Thread;
use rustrt::thread::Thread;
#[test]
fn smoke_lock() {

View File

@ -544,6 +544,8 @@ impl Death {
#[cfg(test)]
mod test {
extern crate rustrt;
use super::*;
use std::prelude::*;
use std::task;
@ -592,7 +594,7 @@ mod test {
#[test]
#[should_fail]
fn test_begin_unwind() {
use std::rt::unwind::begin_unwind;
use rustrt::unwind::begin_unwind;
begin_unwind("cause", &(file!(), line!()))
}

View File

@ -229,7 +229,7 @@ pub mod dl {
}
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire

View File

@ -18,7 +18,7 @@ use kinds::Send;
use option::{Some, None};
use result::Ok;
use rt::backtrace;
use rt::{Stderr, Stdio};
use rustrt::{Stderr, Stdio};
use rustrt::local::Local;
use rustrt::task::Task;
use str::Str;

View File

@ -40,9 +40,9 @@ use option::{Option, Some, None};
use boxed::Box;
use sys::{fs, tty};
use result::{Ok, Err};
use rt;
use rt::local::Local;
use rt::task::Task;
use rustrt;
use rustrt::local::Local;
use rustrt::task::Task;
use slice::SlicePrelude;
use str::StrPrelude;
use uint;
@ -207,7 +207,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
local_stdout.replace(Some(my_stdout));
result
} else {
let mut io = rt::Stdout;
let mut io = rustrt::Stdout;
f(&mut io as &mut Writer)
};
match result {

View File

@ -162,7 +162,6 @@ pub use core::result;
pub use core::option;
pub use alloc::boxed;
pub use alloc::rc;
pub use core_collections::slice;
@ -247,7 +246,7 @@ pub mod fmt;
#[path = "sys/common/mod.rs"] mod sys_common;
mod rt;
pub mod rt;
mod failure;
// A curious inner-module that's not exported that contains the binding

View File

@ -208,7 +208,7 @@ Accessing environment variables is not generally threadsafe.
Serialize access through a global lock.
*/
fn with_env_lock<T>(f: || -> T) -> T {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
@ -1039,9 +1039,9 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> {
target_os = "freebsd",
target_os = "dragonfly"))]
fn real_args_as_bytes() -> Vec<Vec<u8>> {
use rt;
use rustrt;
match rt::args::clone() {
match rustrt::args::clone() {
Some(args) => args,
None => panic!("process arguments not initialized")
}

View File

@ -238,7 +238,7 @@ mod imp {
use mem;
use option::{Some, None, Option};
use result::{Ok, Err};
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
/// As always - iOS on arm uses SjLj exceptions and
/// _Unwind_Backtrace is even not available there. Still,
@ -667,7 +667,7 @@ mod imp {
use option::{Some, None};
use path::Path;
use result::{Ok, Err};
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use slice::SlicePrelude;
use str::StrPrelude;
use dynamic_lib::DynamicLibrary;

View File

@ -66,9 +66,7 @@ pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
// Reexport functionality from librustrt and other crates underneath the
// standard library which work together to create the entire runtime.
pub use alloc::heap;
pub use rustrt::{task, local, mutex, exclusive, stack, args, thread};
pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt};
pub use rustrt::{at_exit, unwind, DEFAULT_ERROR_CODE};
pub use rustrt::{begin_unwind, begin_unwind_fmt, at_exit};
// Simple backtrace functionality (to print on panic)
pub mod backtrace;
@ -84,7 +82,7 @@ mod util;
#[allow(experimental)]
pub fn init(argc: int, argv: *const *const u8) {
rustrt::init(argc, argv);
unsafe { unwind::register(failure::on_fail); }
unsafe { rustrt::unwind::register(failure::on_fail); }
}
#[cfg(any(windows, android))]
@ -147,19 +145,19 @@ pub fn start(argc: int, argv: *const *const u8, main: proc()) -> int {
init(argc, argv);
let mut exit_code = None;
let mut main = Some(main);
let mut task = Task::new(Some((my_stack_bottom, my_stack_top)),
Some(rt::thread::main_guard_page()));
let mut task = box Task::new(Some((my_stack_bottom, my_stack_top)),
Some(rustrt::thread::main_guard_page()));
task.name = Some(str::Slice("<main>"));
drop(task.run(|| {
unsafe {
rt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
rustrt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
}
(main.take().unwrap())();
exit_code = Some(os::get_exit_status());
}).destroy());
unsafe { rt::cleanup(); }
// If the exit code wasn't set, then the task block must have panicked.
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
return exit_code.unwrap_or(rustrt::DEFAULT_ERROR_CODE);
}
/// One-time runtime cleanup.

View File

@ -22,8 +22,8 @@
use mem;
use rustrt::bookkeeping;
use rt::mutex::StaticNativeMutex;
use rt;
use rustrt::mutex::StaticNativeMutex;
use rustrt;
use cell::UnsafeCell;
use sys::helper_signal;
use prelude::*;
@ -83,7 +83,7 @@ impl<M: Send> Helper<M> {
self.lock.lock().signal()
});
rt::at_exit(proc() { self.shutdown() });
rustrt::at_exit(proc() { self.shutdown() });
*self.initialized.get() = true;
}
}

View File

@ -16,7 +16,7 @@ use libc::{mod, c_char, c_int};
use mem;
use num::Int;
use ptr::{mod, null, null_mut};
use rt::mutex;
use rustrt::mutex;
use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};
use io::net::addrinfo;
use io::{IoResult, IoError};

View File

@ -25,7 +25,7 @@ use sys_common::mkerr_libc;
macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
signal: ::cell::UnsafeCell { value: 0 },
initialized: ::cell::UnsafeCell { value: false },

View File

@ -12,7 +12,7 @@ use alloc::arc::Arc;
use libc;
use c_str::CString;
use mem;
use rt::mutex;
use rustrt::mutex;
use sync::atomic;
use io::{mod, IoResult, IoError};
use prelude::*;

View File

@ -26,7 +26,7 @@ use sync::{Once, ONCE_INIT};
macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
signal: ::cell::UnsafeCell { value: 0 },
initialized: ::cell::UnsafeCell { value: false },

View File

@ -90,7 +90,7 @@ use c_str::CString;
use mem;
use ptr;
use sync::atomic;
use rt::mutex;
use rustrt::mutex;
use io::{mod, IoError, IoResult};
use prelude::*;

View File

@ -50,9 +50,9 @@ use kinds::{Send, marker};
use option::{None, Some, Option};
use boxed::Box;
use result::Result;
use rt::local::Local;
use rt::task;
use rt::task::Task;
use rustrt::local::Local;
use rustrt::task;
use rustrt::task::Task;
use str::{Str, SendStr, IntoMaybeOwned};
use string::{String, ToString};
use sync::Future;
@ -142,13 +142,13 @@ impl TaskBuilder {
stack_size: stack_size,
};
if stdout.is_some() || stderr.is_some() {
spawner.spawn(opts, proc() {
Task::spawn(opts, proc() {
let _ = stdout.map(stdio::set_stdout);
let _ = stderr.map(stdio::set_stderr);
f();
})
} else {
spawner.spawn(opts, f)
Task::spawn(opts, f)
}
}
@ -237,7 +237,7 @@ pub fn try_future<T:Send>(f: proc():Send -> T) -> Future<Result<T, Box<Any + Sen
/// Read the name of the current task.
#[stable]
pub fn name() -> Option<String> {
use rt::task::Task;
use rustrt::task::Task;
let task = Local::borrow(None::<Task>);
match task.name {
@ -249,7 +249,7 @@ pub fn name() -> Option<String> {
/// Yield control to the task scheduler.
#[unstable = "Name will change."]
pub fn deschedule() {
use rt::task::Task;
use rustrt::task::Task;
Task::yield_now();
}
@ -257,7 +257,7 @@ pub fn deschedule() {
/// destructor that is run while unwinding the stack after a call to `panic!()`).
#[unstable = "May move to a different module."]
pub fn failing() -> bool {
use rt::task::Task;
use rustrt::task::Task;
Local::borrow(None::<Task>).unwinder.unwinding()
}

View File

@ -336,6 +336,8 @@ macro_rules! test (
mod $name {
#![allow(unused_imports)]
extern crate rustrt;
use std::prelude::*;
use comm::*;
@ -1512,7 +1514,7 @@ mod test {
})
test!(fn sends_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;
let (tx, rx) = channel();
let t = Thread::start(proc() {
@ -1527,7 +1529,7 @@ mod test {
})
test!(fn try_recvs_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;
let (tx, rx) = channel();
let (cdone, pdone) = channel();
@ -1977,7 +1979,7 @@ mod sync_tests {
})
test!(fn try_recvs_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;
let (tx, rx) = sync_channel::<()>(0);
let (cdone, pdone) = channel();

View File

@ -414,7 +414,7 @@ mod tests {
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
use std::mem;
use std::rt::thread::Thread;
use rustrt::thread::Thread;
use std::rand;
use std::rand::Rng;
use atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,

View File

@ -9,9 +9,10 @@
// except according to those terms.
extern crate libc;
extern crate rustrt;
use std::mem;
use std::rt::thread::Thread;
use rustrt::thread::Thread;
#[link(name = "rust_test_helpers")]
extern {

View File

@ -8,9 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate rustrt;
pub fn main() {
unsafe {
let x = Some(::std::rt::exclusive::Exclusive::new(true));
let x = Some(::rustrt::exclusive::Exclusive::new(true));
match x {
Some(ref z) if *z.lock() => {
assert!(*z.lock());

View File

@ -1,28 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-android (FIXME #11419)
extern crate native;
static mut set: bool = false;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
// make sure that native::start always waits for all children to finish
native::start(argc, argv, proc() {
spawn(proc() {
unsafe { set = true; }
});
});
// if we didn't set the global, then return a nonzero code
if unsafe {set} {0} else {1}
}

View File

@ -8,6 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate rustrt;
struct Point {x: int, y: int, z: int}
@ -15,7 +16,7 @@ fn f(p: &mut Point) { p.z = 13; }
pub fn main() {
unsafe {
let x = Some(::std::rt::exclusive::Exclusive::new(true));
let x = Some(::rustrt::exclusive::Exclusive::new(true));
match x {
Some(ref z) if *z.lock() => {
assert!(*z.lock());