Change WASI's RawFd
from u32
to c_int
(i32
).
WASI previously used `u32` as its `RawFd` type, since its "file descriptors" are unsigned table indices, and there's no fundamental reason why WASI can't have more than 2^31 handles. However, this creates myriad little incompability problems with code that also supports Unix platforms, where `RawFd` is `c_int`. While WASI isn't a Unix, it often shares code with Unix, and this difference made such shared code inconvenient. #87329 is the most recent example of such code. So, switch WASI to use `c_int`, which is `i32`. This will mean that code intending to support WASI should ideally avoid assuming that negative file descriptors are invalid, even though POSIX itself says that file descriptors are never negative. This is a breaking change, but `RawFd` is considerd an experimental feature in [the documentation]. [the documentation]: https://doc.rust-lang.org/stable/std/os/wasi/io/type.RawFd.html
This commit is contained in:
parent
8df945c471
commit
35de5c9b35
5 changed files with 83 additions and 54 deletions
|
@ -6,11 +6,18 @@
|
|||
use crate::fs;
|
||||
use crate::io;
|
||||
use crate::net;
|
||||
use crate::os::raw;
|
||||
use crate::sys;
|
||||
use crate::sys_common::{AsInner, FromInner, IntoInner};
|
||||
|
||||
/// Raw file descriptors.
|
||||
pub type RawFd = u32;
|
||||
///
|
||||
/// This has type `c_int` to ease compatibility with code that also compiles on
|
||||
/// Unix configurations, however unlike Unix and POSIX, in WASI negative file
|
||||
/// descriptors are valid. Only `-1` is reserved for indicating errors. Code
|
||||
/// intending to be portable across Unix platforms and WASI should avoid
|
||||
/// assuming that negative file descriptors are invalid.
|
||||
pub type RawFd = raw::c_int;
|
||||
|
||||
/// A trait to extract the raw WASI file descriptor from an underlying
|
||||
/// object.
|
||||
|
@ -161,41 +168,41 @@ impl IntoRawFd for fs::File {
|
|||
impl AsRawFd for io::Stdin {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDIN_FILENO as RawFd
|
||||
libc::STDIN_FILENO
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for io::Stdout {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDOUT_FILENO as RawFd
|
||||
libc::STDOUT_FILENO
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for io::Stderr {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDERR_FILENO as RawFd
|
||||
libc::STDERR_FILENO
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRawFd for io::StdinLock<'a> {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDIN_FILENO as RawFd
|
||||
libc::STDIN_FILENO
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRawFd for io::StdoutLock<'a> {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDOUT_FILENO as RawFd
|
||||
libc::STDOUT_FILENO
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> AsRawFd for io::StderrLock<'a> {
|
||||
#[inline]
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
libc::STDERR_FILENO as RawFd
|
||||
libc::STDERR_FILENO
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue