]> git.lizzy.rs Git - rust.git/commitdiff
Make most of std::rt private
authorAaron Turon <aturon@mozilla.com>
Sat, 15 Nov 2014 00:30:16 +0000 (16:30 -0800)
committerAaron Turon <aturon@mozilla.com>
Fri, 21 Nov 2014 01:19:24 +0000 (17:19 -0800)
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]

24 files changed:
src/libcollections/slice.rs
src/librustrt/local.rs
src/librustrt/mutex.rs
src/librustrt/task.rs
src/libstd/dynamic_lib.rs
src/libstd/failure.rs
src/libstd/io/stdio.rs
src/libstd/lib.rs
src/libstd/os.rs
src/libstd/rt/backtrace.rs
src/libstd/rt/mod.rs
src/libstd/sys/common/helper_thread.rs
src/libstd/sys/common/net.rs
src/libstd/sys/unix/mod.rs
src/libstd/sys/unix/pipe.rs
src/libstd/sys/windows/mod.rs
src/libstd/sys/windows/pipe.rs
src/libstd/task.rs
src/libsync/comm/mod.rs
src/libsync/deque.rs
src/test/run-pass/foreign-call-no-runtime.rs
src/test/run-pass/match-ref-binding-in-guard-3256.rs
src/test/run-pass/native-always-waits.rs [deleted file]
src/test/run-pass/writealias.rs

index 4a54b361001ceba9a07914676bdccf0b2cce7a61..c3a248ce3185b318d29a4d7c9587364f055c3fe7 100644 (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 @@ fn test_swap_remove() {
     #[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);
index 8531f569a6b1215f83cec0e204dc80b73ef0156b..93c5508e0426f4f521902367717ec71981a14645 100644 (file)
@@ -52,8 +52,10 @@ unsafe fn try_unsafe_borrow() -> Option<*mut 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;
 
index 1c448736d3ec1ca794520857cf40278d7af31ca1..11f601593632920bb72a5e3432a6277facbb1037 100644 (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 @@ pub unsafe fn new() -> 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 @@ pub unsafe fn new() -> NativeMutex {
     /// # Example
     ///
     /// ```rust
-    /// use std::rt::mutex::NativeMutex;
+    /// use rustrt::mutex::NativeMutex;
     /// unsafe {
     ///     let mut lock = NativeMutex::new();
     ///
@@ -649,11 +649,13 @@ fn InitializeCriticalSectionAndSpinCount(
 
 #[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() {
index 34c913c5bcb40e52305350f1e2469c34e9ae5492..cec28a464f8b1e01e9df3d356215ce008d92b31f 100644 (file)
@@ -544,6 +544,8 @@ pub fn new() -> Death {
 
 #[cfg(test)]
 mod test {
+    extern crate rustrt;
+
     use super::*;
     use std::prelude::*;
     use std::task;
@@ -592,7 +594,7 @@ fn comm_shared_chan() {
     #[test]
     #[should_fail]
     fn test_begin_unwind() {
-        use std::rt::unwind::begin_unwind;
+        use rustrt::unwind::begin_unwind;
         begin_unwind("cause", &(file!(), line!()))
     }
 
index 8bb82d5bc1e82bc188292bef9ec70b7e10c00c93..0f119d44485324afb179db12abf4eb7e55effe44 100644 (file)
@@ -229,7 +229,7 @@ pub unsafe fn open_internal() -> *mut u8 {
     }
 
     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
index 077599743564151b5b72ec5cd43184d26d71044c..c23e043c174091876a60189b0c7f44a229148407 100644 (file)
@@ -18,7 +18,7 @@
 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;
index 362e80f9f12c37e325ddab97e623fe0b7283e1b1..7374668a69d834c1cbfa961e1a20ab2ace2c990e 100644 (file)
@@ -40,9 +40,9 @@
 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 {
index c27faea74bb8f56f560ea350585017f660de2729..b35c49efdd80cfee79aea45e806dd39ed5b7390c 100644 (file)
 pub use core::option;
 
 pub use alloc::boxed;
-
 pub use alloc::rc;
 
 pub use core_collections::slice;
 
 #[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
index 68ddabfd48f279f2e420c851ffcb2e8b40a0fe8b..d7ba4877086ea2275a617c5339f5c3974083ce16 100644 (file)
@@ -208,7 +208,7 @@ pub fn fill_utf16_buf_and_decode(f: |*mut u16, DWORD| -> DWORD)
 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")
     }
index 11257d506b0e0c344140efdf61de9fd647b4ab8c..107518ef27c9d818457f6088728217a2e306b311 100644 (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;
index b6e57186afef19c736c3aa367d6140c2e8af1f07..21b4edb6375812650620195b7fa6a222c9ec6987 100644 (file)
@@ -66,9 +66,7 @@
 // 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 @@
 #[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.
index d7c286bf0b9f2e85cbfd8c1c62a1f666216ca1b2..9508d8d92325bab97d0022c4dc31a068a170552c 100644 (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 @@ pub fn boot<T: Send>(&'static self,
                     self.lock.lock().signal()
                 });
 
-                rt::at_exit(proc() { self.shutdown() });
+                rustrt::at_exit(proc() { self.shutdown() });
                 *self.initialized.get() = true;
             }
         }
index 9b2b594a9c7cde8574ec1c1dc5800b24df306b1c..029fc8527426152cf61e6c073d240634c146c35b 100644 (file)
@@ -16,7 +16,7 @@
 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};
index 4db9e8a9df8b5a98a2c7a989df6c83773342b2b1..664a6a1e70c767b1b3b1f17d6a4b48782642f462 100644 (file)
@@ -25,7 +25,7 @@
 
 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 },
index 3fba06e0c7f1c4f6c159c9bbd1e0c062127075d4..4d3469a9c24a80d19e55f84015f2da512519765a 100644 (file)
@@ -12,7 +12,7 @@
 use libc;
 use c_str::CString;
 use mem;
-use rt::mutex;
+use rustrt::mutex;
 use sync::atomic;
 use io::{mod, IoResult, IoError};
 use prelude::*;
index f316b2d8493f4dbc75cfa1cd9237d12d26f8dbcf..815ace21f879d931f80bbe8e2a5f2b915b7a86b2 100644 (file)
@@ -26,7 +26,7 @@
 
 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 },
index e38202302fb0eb58a11a5fe26be5581a3f912e05..a623c2cd8e29737ba9e34a72e576f9f967404bab 100644 (file)
@@ -90,7 +90,7 @@
 use mem;
 use ptr;
 use sync::atomic;
-use rt::mutex;
+use rustrt::mutex;
 use io::{mod, IoError, IoResult};
 use prelude::*;
 
index 8da32ba4b89cd1c5bcdbcdee093e3e33b45caab6..4f5f47e980c0dbc4bed01abe8303c3b11b447e80 100644 (file)
@@ -50,9 +50,9 @@
 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 @@ fn spawn_internal(self, f: proc():Send,
             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()
 }
 
index 02fdc69448ef70af2152a5ac608962118034276b..3c7e46036d6fbe689800ac25cf192d84c709a745 100644 (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 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     })
 
     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 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     })
 
     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 @@ fn recv(rx: Receiver<Box<int>>, i: int) {
     })
 
     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();
index 2f5c455556c8f797150018d064ea2fc625f20314..1fece03b27364bb2194b1d69d8e19d4eef8d9185 100644 (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,
index 9dd52dfb6da0e42894be3b10692ed8ad9c665d33..af36387f06c2c9fb46d32ace369c0518507529ad 100644 (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 {
index 243c87c0eeb0095221cb2d5105ee77754879691c..ac783961b508e8363d8f492a8cd6afa0edea23b2 100644 (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());
diff --git a/src/test/run-pass/native-always-waits.rs b/src/test/run-pass/native-always-waits.rs
deleted file mode 100644 (file)
index ea3eb29..0000000
+++ /dev/null
@@ -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}
-}
index ae49c07093b11818fbce833496afa8228dff3ce8..c8d281a791c90f760a1e0653b56d84768bad3894 100644 (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 @@ struct Point {x: int, y: int, z: int}
 
 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());