diff options
| author | bors <bors@rust-lang.org> | 2015-03-13 20:22:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-03-13 20:22:16 +0000 |
| commit | 3e4be02b80a3dd27bce20870958fe0aef7e7336d (patch) | |
| tree | 156b54e84eeb1df2818be29b53ab7f35b5bc80f0 /src/libstd/sys/windows | |
| parent | 9eb69abad8ffbce840e7dc7038ddea434dc987f1 (diff) | |
| parent | 981bf5f690d1d7c5cf3e1419ac7a7c86dbc7a4d5 (diff) | |
| download | rust-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/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/backtrace.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/windows/condvar.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/windows/ext.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/windows/pipe.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stdio.rs | 10 | ||||
| -rw-r--r-- | src/libstd/sys/windows/timer.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/tty.rs | 2 |
9 files changed, 38 insertions, 7 deletions
diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index b464ba70911..8638099ca69 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -28,9 +28,10 @@ use prelude::v1::*; use dynamic_lib::DynamicLibrary; +use io; +use io::prelude::*; use ffi::CStr; use intrinsics; -use old_io::IoResult; use libc; use mem; use ptr; @@ -292,7 +293,7 @@ impl Drop for Cleanup { fn drop(&mut self) { (self.SymCleanup)(self.handle); } } -pub fn write(w: &mut Writer) -> IoResult<()> { +pub fn write(w: &mut Write) -> io::Result<()> { // According to windows documentation, all dbghelp functions are // single-threaded. static LOCK: StaticMutex = MUTEX_INIT; diff --git a/src/libstd/sys/windows/condvar.rs b/src/libstd/sys/windows/condvar.rs index 071637e3a93..67552255fdb 100644 --- a/src/libstd/sys/windows/condvar.rs +++ b/src/libstd/sys/windows/condvar.rs @@ -12,7 +12,7 @@ use prelude::v1::*; use cell::UnsafeCell; use libc::{self, DWORD}; -use os; +use sys::os; use sys::mutex::{self, Mutex}; use sys::sync as ffi; use time::Duration; @@ -46,7 +46,7 @@ impl Condvar { 0); if r == 0 { const ERROR_TIMEOUT: DWORD = 0x5B4; - debug_assert_eq!(os::errno() as uint, ERROR_TIMEOUT as uint); + debug_assert_eq!(os::errno() as usize, ERROR_TIMEOUT as usize); false } else { true diff --git a/src/libstd/sys/windows/ext.rs b/src/libstd/sys/windows/ext.rs index 1d63da813c9..dc820a4ce45 100644 --- a/src/libstd/sys/windows/ext.rs +++ b/src/libstd/sys/windows/ext.rs @@ -25,6 +25,7 @@ use net; use sys::os_str::Buf; use sys_common::{AsInner, FromInner, AsInnerMut}; +#[allow(deprecated)] use old_io; /// Raw HANDLEs. @@ -52,6 +53,7 @@ impl AsRawHandle for fs::File { } } +#[allow(deprecated)] impl AsRawHandle for old_io::pipe::PipeStream { fn as_raw_handle(&self) -> Handle { self.as_inner().handle() diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 46085826e60..6b0f6a78c85 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -64,6 +64,7 @@ pub type msglen_t = libc::c_int; pub unsafe fn close_sock(sock: sock_t) { let _ = libc::closesocket(sock); } // windows has zero values as errors +#[allow(deprecated)] fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> { if ret == 0 { Err(last_error()) @@ -72,6 +73,7 @@ fn mkerr_winbool(ret: libc::c_int) -> IoResult<()> { } } +#[allow(deprecated)] pub fn last_error() -> IoError { let errno = os::errno() as i32; let mut err = decode_error(errno); @@ -79,6 +81,7 @@ pub fn last_error() -> IoError { err } +#[allow(deprecated)] pub fn last_net_error() -> IoError { let errno = unsafe { c::WSAGetLastError() as i32 }; let mut err = decode_error(errno); @@ -86,11 +89,13 @@ pub fn last_net_error() -> IoError { err } +#[allow(deprecated)] pub fn last_gai_error(_errno: i32) -> IoError { last_net_error() } /// Convert an `errno` value into a high-level error variant and description. +#[allow(deprecated)] pub fn decode_error(errno: i32) -> IoError { let (kind, desc) = match errno { libc::EOF => (old_io::EndOfFile, "end of file"), @@ -134,6 +139,7 @@ pub fn decode_error(errno: i32) -> IoError { IoError { kind: kind, desc: desc, detail: None } } +#[allow(deprecated)] pub fn decode_error_detailed(errno: i32) -> IoError { let mut err = decode_error(errno); err.detail = Some(os::error_string(errno)); @@ -178,11 +184,13 @@ pub fn ms_to_timeval(ms: u64) -> libc::timeval { } } +#[allow(deprecated)] pub fn wouldblock() -> bool { let err = os::errno(); err == libc::WSAEWOULDBLOCK as i32 } +#[allow(deprecated)] pub fn set_nonblocking(fd: sock_t, nb: bool) { let mut set = nb as libc::c_ulong; if unsafe { c::ioctlsocket(fd, c::FIONBIO, &mut set) } != 0 { @@ -205,6 +213,7 @@ pub fn init_net() { } } +#[allow(deprecated)] pub fn to_utf16(s: Option<&str>) -> IoResult<Vec<u16>> { match s { Some(s) => Ok(to_utf16_os(OsStr::from_str(s))), @@ -283,6 +292,7 @@ fn fill_utf16_buf_base<F1, F2, T>(mut f1: F1, f2: F2) -> Result<T, ()> } } +#[allow(deprecated)] fn fill_utf16_buf<F1, F2, T>(f1: F1, f2: F2) -> IoResult<T> where F1: FnMut(*mut u16, libc::DWORD) -> libc::DWORD, F2: FnOnce(&[u16]) -> T diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 89cf8a08a68..ecd538abfb4 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -22,6 +22,7 @@ use io; use libc::types::os::arch::extra::LPWCH; use libc::{self, c_int, c_void}; use mem; +#[allow(deprecated)] use old_io::{IoError, IoResult}; use ops::Range; use path::{self, PathBuf}; @@ -134,7 +135,7 @@ pub fn env() -> Env { let ch = GetEnvironmentStringsW(); if ch as usize == 0 { panic!("failure getting env string from OS: {}", - IoError::last_error()); + io::Error::last_os_error()); } Env { base: ch, cur: ch } } @@ -269,7 +270,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) { unsafe { if libc::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) == 0 { - panic!("failed to set env: {}", IoError::last_error()); + panic!("failed to set env: {}", io::Error::last_os_error()); } } } @@ -278,7 +279,7 @@ pub fn unsetenv(n: &OsStr) { let v = super::to_utf16_os(n); unsafe { if libc::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) == 0 { - panic!("failed to unset env: {}", IoError::last_error()); + panic!("failed to unset env: {}", io::Error::last_os_error()); } } } @@ -333,6 +334,7 @@ pub fn page_size() -> usize { } } +#[allow(deprecated)] pub unsafe fn pipe() -> IoResult<(FileDesc, FileDesc)> { // Windows pipes work subtly differently than unix pipes, and their // inheritance has to be handled in a different way that I do not diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 1f228b7d32e..2b03e9e7431 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -84,6 +84,8 @@ //! the test suite passing (the suite is in libstd), and that's good enough for //! me! +#![allow(deprecated)] + use prelude::v1::*; use libc; diff --git a/src/libstd/sys/windows/stdio.rs b/src/libstd/sys/windows/stdio.rs index 72ce8b7c6e3..d1bff0e135d 100644 --- a/src/libstd/sys/windows/stdio.rs +++ b/src/libstd/sys/windows/stdio.rs @@ -135,6 +135,16 @@ impl Stderr { } } +// FIXME: right now this raw stderr handle is used in a few places because +// std::io::stderr_raw isn't exposed, but once that's exposed this impl +// should go away +impl io::Write for Stderr { + fn write(&mut self, data: &[u8]) -> io::Result<usize> { + Stderr::write(self, data) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } +} + impl NoClose { fn new(handle: libc::HANDLE) -> NoClose { NoClose(Some(Handle::new(handle))) diff --git a/src/libstd/sys/windows/timer.rs b/src/libstd/sys/windows/timer.rs index a23a90a9cf8..91a7f694181 100644 --- a/src/libstd/sys/windows/timer.rs +++ b/src/libstd/sys/windows/timer.rs @@ -20,6 +20,8 @@ //! Other than that, the implementation is pretty straightforward in terms of //! the other two implementations of timers with nothing *that* new showing up. +#![allow(deprecated)] + use prelude::v1::*; use self::Req::*; diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index 37dce423a68..f542cb2323e 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -25,6 +25,8 @@ //! wrapper that performs encoding/decoding, this implementation should switch //! to working in raw UTF-16, with such a wrapper around it. +#![allow(deprecated)] + use prelude::v1::*; use old_io::{self, IoError, IoResult, MemReader}; |
