about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-13 20:22:16 +0000
committerbors <bors@rust-lang.org>2015-03-13 20:22:16 +0000
commit3e4be02b80a3dd27bce20870958fe0aef7e7336d (patch)
tree156b54e84eeb1df2818be29b53ab7f35b5bc80f0 /src/libstd/rt
parent9eb69abad8ffbce840e7dc7038ddea434dc987f1 (diff)
parent981bf5f690d1d7c5cf3e1419ac7a7c86dbc7a4d5 (diff)
downloadrust-3e4be02b80a3dd27bce20870958fe0aef7e7336d.tar.gz
rust-3e4be02b80a3dd27bce20870958fe0aef7e7336d.zip
Auto merge of #23292 - alexcrichton:stabilize-io, r=aturon
The new `std::io` module has had some time to bake now, and this commit
stabilizes its functionality. There are still portions of the module which
remain unstable, and below contains a summart of the actions taken.

This commit also deprecates the entire contents of the `old_io` module in a
blanket fashion. All APIs should now have a reasonable replacement in the
new I/O modules.

Stable APIs:

* `std::io` (the name)
* `std::io::prelude` (the name)
* `Read`
* `Read::read`
* `Read::{read_to_end, read_to_string}` after being modified to return a `usize`
  for the number of bytes read.
* `ReadExt`
* `Write`
* `Write::write`
* `Write::{write_all, write_fmt}`
* `WriteExt`
* `BufRead`
* `BufRead::{fill_buf, consume}`
* `BufRead::{read_line, read_until}` after being modified to return a `usize`
  for the number of bytes read.
* `BufReadExt`
* `BufReader`
* `BufReader::{new, with_capacity}`
* `BufReader::{get_ref, get_mut, into_inner}`
* `{Read,BufRead} for BufReader`
* `BufWriter`
* `BufWriter::{new, with_capacity}`
* `BufWriter::{get_ref, get_mut, into_inner}`
* `Write for BufWriter`
* `IntoInnerError`
* `IntoInnerError::{error, into_inner}`
* `{Error,Display} for IntoInnerError`
* `LineWriter`
* `LineWriter::{new, with_capacity}` - `with_capacity` was added
* `LineWriter::{get_ref, get_mut, into_inner}` - `get_mut` was added)
* `Write for LineWriter`
* `BufStream`
* `BufStream::{new, with_capacities}`
* `BufStream::{get_ref, get_mut, into_inner}`
* `{BufRead,Read,Write} for BufStream`
* `stdin`
* `Stdin`
* `Stdin::lock`
* `Stdin::read_line` - added method
* `StdinLock`
* `Read for Stdin`
* `{Read,BufRead} for StdinLock`
* `stdout`
* `Stdout`
* `Stdout::lock`
* `StdoutLock`
* `Write for Stdout`
* `Write for StdoutLock`
* `stderr`
* `Stderr`
* `Stderr::lock`
* `StderrLock`
* `Write for Stderr`
* `Write for StderrLock`
* `io::Result`
* `io::Error`
* `io::Error::last_os_error`
* `{Display, Error} for Error`

Unstable APIs:

(reasons can be found in the commit itself)

* `Write::flush`
* `Seek`
* `ErrorKind`
* `Error::new`
* `Error::from_os_error`
* `Error::kind`

Deprecated APIs

* `Error::description` - available via the `Error` trait
* `Error::detail` - available via the `Display` implementation
* `thread::Builder::{stdout, stderr}`

Changes in functionality:

* `old_io::stdio::set_stderr` is now a noop as the infrastructure for printing
  backtraces has migrated to `std::io`.

[breaking-change]
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/util.rs73
1 files changed, 7 insertions, 66 deletions
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index dc557403153..e72fd7b3320 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -11,16 +11,14 @@
 // ignore-lexer-test FIXME #15677
 
 use prelude::v1::*;
+use io::prelude::*;
 
-use cmp;
 use env;
 use fmt;
 use intrinsics;
-use libc::{self, uintptr_t};
-use os;
-use slice;
-use str;
+use libc::uintptr_t;
 use sync::atomic::{self, Ordering};
+use sys::stdio::Stderr;
 
 /// Dynamically inquire about whether we're running under V.
 /// You should usually not use this unless your test definitely
@@ -62,7 +60,9 @@ pub fn min_stack() -> uint {
 
 /// Get's the number of scheduler threads requested by the environment
 /// either `RUST_THREADS` or `num_cpus`.
+#[allow(deprecated)]
 pub fn default_sched_threads() -> uint {
+    use os;
     match env::var("RUST_THREADS") {
         Ok(nstr) => {
             let opt_n: Option<uint> = nstr.parse().ok();
@@ -88,76 +88,17 @@ pub fn default_sched_threads() -> uint {
 pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) ||
                                   cfg!(rtassert);
 
-pub struct Stdio(libc::c_int);
-
-#[allow(non_upper_case_globals)]
-pub const Stdout: Stdio = Stdio(libc::STDOUT_FILENO);
-#[allow(non_upper_case_globals)]
-pub const Stderr: Stdio = Stdio(libc::STDERR_FILENO);
-
-impl Stdio {
-    pub fn write_bytes(&mut self, data: &[u8]) {
-        #[cfg(unix)]
-        type WriteLen = libc::size_t;
-        #[cfg(windows)]
-        type WriteLen = libc::c_uint;
-        unsafe {
-            let Stdio(fd) = *self;
-            libc::write(fd,
-                        data.as_ptr() as *const libc::c_void,
-                        data.len() as WriteLen);
-        }
-    }
-}
-
-impl fmt::Write for Stdio {
-    fn write_str(&mut self, data: &str) -> fmt::Result {
-        self.write_bytes(data.as_bytes());
-        Ok(()) // yes, we're lying
-    }
-}
-
 pub fn dumb_print(args: fmt::Arguments) {
-    let _ = Stderr.write_fmt(args);
+    let _ = write!(&mut Stderr::new(), "{}", args);
 }
 
 pub fn abort(args: fmt::Arguments) -> ! {
-    use fmt::Write;
-
-    struct BufWriter<'a> {
-        buf: &'a mut [u8],
-        pos: uint,
-    }
-    impl<'a> fmt::Write for BufWriter<'a> {
-        fn write_str(&mut self, bytes: &str) -> fmt::Result {
-            let left = &mut self.buf[self.pos..];
-            let to_write = &bytes.as_bytes()[..cmp::min(bytes.len(), left.len())];
-            slice::bytes::copy_memory(left, to_write);
-            self.pos += to_write.len();
-            Ok(())
-        }
-    }
-
-    // Convert the arguments into a stack-allocated string
-    let mut msg = [0; 512];
-    let mut w = BufWriter { buf: &mut msg, pos: 0 };
-    let _ = write!(&mut w, "{}", args);
-    let msg = str::from_utf8(&w.buf[..w.pos]).unwrap_or("aborted");
-    let msg = if msg.is_empty() {"aborted"} else {msg};
-    rterrln!("fatal runtime error: {}", msg);
+    rterrln!("fatal runtime error: {}", args);
     unsafe { intrinsics::abort(); }
 }
 
 pub unsafe fn report_overflow() {
     use thread;
-
-    // See the message below for why this is not emitted to the
-    // ^ Where did the message below go?
-    // task's logger. This has the additional conundrum of the
-    // logger may not be initialized just yet, meaning that an FFI
-    // call would happen to initialized it (calling out to libuv),
-    // and the FFI call needs 2MB of stack when we just ran out.
-
     rterrln!("\nthread '{}' has overflowed its stack",
              thread::current().name().unwrap_or("<unknown>"));
 }