Skip to content

Commit 3a527f2

Browse files
committed
Runtime removal: add private sys, sys_common modules
These modules will house the code that used to be part of the runtime system in libnative. The `sys_common` module contains a few low-level but cross-platform details. The `sys` module is set up using `#[cfg()]` to include either a unix or windows implementation of a common API surface. This API surface is *not* exported directly in `libstd`, but is instead used to bulid `std::os` and `std::io`. Ultimately, the low-level details in `sys` will be exposed in a controlled way through a separate platform-specific surface, but that setup is not part of this patch.
1 parent 93c85eb commit 3a527f2

File tree

12 files changed

+592
-456
lines changed

12 files changed

+592
-456
lines changed

src/libnative/io/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ pub mod pipe;
7373
#[path = "tty_windows.rs"]
7474
mod tty;
7575

76-
#[cfg(unix)] #[path = "c_unix.rs"] mod c;
77-
#[cfg(windows)] #[path = "c_windows.rs"] mod c;
78-
7976
fn unimpl() -> IoError {
8077
#[cfg(unix)] use libc::ENOSYS as ERROR;
8178
#[cfg(windows)] use libc::ERROR_CALL_NOT_IMPLEMENTED as ERROR;

src/libnative/io/util.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.

src/libstd/io/mod.rs

Lines changed: 5 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ use os;
236236
use boxed::Box;
237237
use result::{Ok, Err, Result};
238238
use rt::rtio;
239-
use slice::{AsSlice, SlicePrelude};
240-
use str::{Str, StrPrelude};
239+
use sys;
241240
use str;
242241
use string::String;
243242
use uint;
@@ -312,91 +311,10 @@ impl IoError {
312311
/// struct is filled with an allocated string describing the error
313312
/// in more detail, retrieved from the operating system.
314313
pub fn from_errno(errno: uint, detail: bool) -> IoError {
315-
316-
#[cfg(windows)]
317-
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
318-
match errno {
319-
libc::EOF => (EndOfFile, "end of file"),
320-
libc::ERROR_NO_DATA => (BrokenPipe, "the pipe is being closed"),
321-
libc::ERROR_FILE_NOT_FOUND => (FileNotFound, "file not found"),
322-
libc::ERROR_INVALID_NAME => (InvalidInput, "invalid file name"),
323-
libc::WSAECONNREFUSED => (ConnectionRefused, "connection refused"),
324-
libc::WSAECONNRESET => (ConnectionReset, "connection reset"),
325-
libc::ERROR_ACCESS_DENIED | libc::WSAEACCES =>
326-
(PermissionDenied, "permission denied"),
327-
libc::WSAEWOULDBLOCK => {
328-
(ResourceUnavailable, "resource temporarily unavailable")
329-
}
330-
libc::WSAENOTCONN => (NotConnected, "not connected"),
331-
libc::WSAECONNABORTED => (ConnectionAborted, "connection aborted"),
332-
libc::WSAEADDRNOTAVAIL => (ConnectionRefused, "address not available"),
333-
libc::WSAEADDRINUSE => (ConnectionRefused, "address in use"),
334-
libc::ERROR_BROKEN_PIPE => (EndOfFile, "the pipe has ended"),
335-
libc::ERROR_OPERATION_ABORTED =>
336-
(TimedOut, "operation timed out"),
337-
libc::WSAEINVAL => (InvalidInput, "invalid argument"),
338-
libc::ERROR_CALL_NOT_IMPLEMENTED =>
339-
(IoUnavailable, "function not implemented"),
340-
libc::ERROR_INVALID_HANDLE =>
341-
(MismatchedFileTypeForOperation,
342-
"invalid handle provided to function"),
343-
libc::ERROR_NOTHING_TO_TERMINATE =>
344-
(InvalidInput, "no process to kill"),
345-
346-
// libuv maps this error code to EISDIR. we do too. if it is found
347-
// to be incorrect, we can add in some more machinery to only
348-
// return this message when ERROR_INVALID_FUNCTION after certain
349-
// Windows calls.
350-
libc::ERROR_INVALID_FUNCTION => (InvalidInput,
351-
"illegal operation on a directory"),
352-
353-
_ => (OtherIoError, "unknown error")
354-
}
355-
}
356-
357-
#[cfg(not(windows))]
358-
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
359-
// FIXME: this should probably be a bit more descriptive...
360-
match errno {
361-
libc::EOF => (EndOfFile, "end of file"),
362-
libc::ECONNREFUSED => (ConnectionRefused, "connection refused"),
363-
libc::ECONNRESET => (ConnectionReset, "connection reset"),
364-
libc::EPERM | libc::EACCES =>
365-
(PermissionDenied, "permission denied"),
366-
libc::EPIPE => (BrokenPipe, "broken pipe"),
367-
libc::ENOTCONN => (NotConnected, "not connected"),
368-
libc::ECONNABORTED => (ConnectionAborted, "connection aborted"),
369-
libc::EADDRNOTAVAIL => (ConnectionRefused, "address not available"),
370-
libc::EADDRINUSE => (ConnectionRefused, "address in use"),
371-
libc::ENOENT => (FileNotFound, "no such file or directory"),
372-
libc::EISDIR => (InvalidInput, "illegal operation on a directory"),
373-
libc::ENOSYS => (IoUnavailable, "function not implemented"),
374-
libc::EINVAL => (InvalidInput, "invalid argument"),
375-
libc::ENOTTY =>
376-
(MismatchedFileTypeForOperation,
377-
"file descriptor is not a TTY"),
378-
libc::ETIMEDOUT => (TimedOut, "operation timed out"),
379-
libc::ECANCELED => (TimedOut, "operation aborted"),
380-
381-
// These two constants can have the same value on some systems,
382-
// but different values on others, so we can't use a match
383-
// clause
384-
x if x == libc::EAGAIN || x == libc::EWOULDBLOCK =>
385-
(ResourceUnavailable, "resource temporarily unavailable"),
386-
387-
_ => (OtherIoError, "unknown error")
388-
}
389-
}
390-
391-
let (kind, desc) = get_err(errno as i32);
392-
IoError {
393-
kind: kind,
394-
desc: desc,
395-
detail: if detail && kind == OtherIoError {
396-
Some(os::error_string(errno).as_slice().chars().map(|c| c.to_lowercase()).collect())
397-
} else {
398-
None
399-
},
314+
let mut err = sys::decode_error(errno as i32);
315+
if detail && err.kind == OtherIoError {
316+
err.detail = Some(os::error_string(errno).as_slice().chars()
317+
.map(|c| c.to_lowercase()).collect())
400318
}
401319
}
402320

src/libstd/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,13 @@ pub mod io;
242242
pub mod path;
243243
pub mod fmt;
244244

245+
#[cfg(unix)]
246+
#[path = "sys/unix/mod.rs"] mod sys;
247+
#[cfg(windows)]
248+
#[path = "sys/windows/mod.rs"] mod sys;
249+
250+
#[path = "sys/common/mod.rs"] mod sys_common;
251+
245252
// FIXME #7809: This shouldn't be pub, and it should be reexported under 'unstable'
246253
// but name resolution doesn't work without it being pub.
247254
pub mod rt;

0 commit comments

Comments
 (0)