From 590386a388cff8af31515c0b740b8124b3d76bc4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 20 Aug 2024 17:39:25 -0700 Subject: [PATCH] Fix compilation errors with `feature = io_safety`. Fix a typo of "io-safety" in place of "io_safety", and fix various compilation errors exposed by this fix. --- src/fs/file.rs | 2 +- src/io/stderr.rs | 4 +++- src/io/stdin.rs | 6 ++++-- src/io/stdout.rs | 4 +++- src/net/tcp/stream.rs | 2 +- src/net/udp/mod.rs | 2 +- src/os/unix/net/datagram.rs | 4 ++-- src/os/unix/net/listener.rs | 4 ++-- src/os/unix/net/stream.rs | 6 +++--- src/utils.rs | 2 +- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/fs/file.rs b/src/fs/file.rs index 67dfbe7f5..7dc12dd0e 100644 --- a/src/fs/file.rs +++ b/src/fs/file.rs @@ -461,7 +461,7 @@ cfg_unix! { impl From for OwnedFd { fn from(val: File) -> OwnedFd { - self.into_std_file().into() + val.into_std_file().into() } } } diff --git a/src/io/stderr.rs b/src/io/stderr.rs index 3f38e8dea..ca8d23d5f 100644 --- a/src/io/stderr.rs +++ b/src/io/stderr.rs @@ -186,7 +186,9 @@ cfg_unix! { impl AsFd for Stderr { fn as_fd(&self) -> BorrowedFd<'_> { - std::io::stderr().as_fd() + unsafe { + BorrowedFd::borrow_raw(std::io::stderr().as_raw_fd()) + } } } } diff --git a/src/io/stdin.rs b/src/io/stdin.rs index 52c31f110..b994bcd07 100644 --- a/src/io/stdin.rs +++ b/src/io/stdin.rs @@ -210,9 +210,11 @@ cfg_unix! { cfg_io_safety! { use crate::os::unix::io::{AsFd, BorrowedFd}; - impl AsFd for Stderr { + impl AsFd for Stdin { fn as_fd(&self) -> BorrowedFd<'_> { - std::io::stdin().as_fd() + unsafe { + BorrowedFd::borrow_raw(std::io::stdin().as_raw_fd()) + } } } } diff --git a/src/io/stdout.rs b/src/io/stdout.rs index c1cd2bcfb..2444bbd7d 100644 --- a/src/io/stdout.rs +++ b/src/io/stdout.rs @@ -186,7 +186,9 @@ cfg_unix! { impl AsFd for Stdout { fn as_fd(&self) -> BorrowedFd<'_> { - std::io::stdout().as_fd() + unsafe { + BorrowedFd::borrow_raw(std::io::stdout().as_raw_fd()) + } } } } diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index 955df82d0..a6cbc927c 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -434,7 +434,7 @@ cfg_unix! { impl From for OwnedFd { fn from(stream: TcpStream) -> OwnedFd { - stream.watcher.into_inner().unwrap().into() + stream.watcher.get_ref().try_clone().unwrap().into() } } } diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 90fdf3e25..7c8798f5c 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -574,7 +574,7 @@ cfg_unix! { impl From for UdpSocket { fn from(fd: OwnedFd) -> UdpSocket { - std::net::TcpStream::from(fd).into() + std::net::UdpSocket::from(fd).into() } } diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 3a92c78b7..792860223 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -352,7 +352,7 @@ cfg_io_safety! { impl From for UnixDatagram { fn from(fd: OwnedFd) -> UnixDatagram { - std::net::TcpStream::from(fd).into() + StdUnixDatagram::from(fd).into() } } @@ -361,4 +361,4 @@ cfg_io_safety! { stream.watcher.into_inner().unwrap().into() } } -} \ No newline at end of file +} diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index 48a6e36d7..b87b781f2 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -245,7 +245,7 @@ cfg_io_safety! { impl From for UnixListener { fn from(fd: OwnedFd) -> UnixListener { - std::net::TcpStream::from(fd).into() + std::os::unix::net::UnixListener::from(fd).into() } } @@ -254,4 +254,4 @@ cfg_io_safety! { stream.watcher.into_inner().unwrap().into() } } -} \ No newline at end of file +} diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index 9a2387b10..4a4f45ad6 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -276,13 +276,13 @@ cfg_io_safety! { impl From for UnixStream { fn from(fd: OwnedFd) -> UnixStream { - std::net::TcpStream::from(fd).into() + std::os::unix::net::UnixStream::from(fd).into() } } impl From for OwnedFd { fn from(stream: UnixStream) -> OwnedFd { - stream.watcher.into_inner().unwrap().into() + stream.watcher.get_ref().try_clone().unwrap().into() } } -} \ No newline at end of file +} diff --git a/src/utils.rs b/src/utils.rs index e541b82e6..853ace0e9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -246,7 +246,7 @@ macro_rules! cfg_default { macro_rules! cfg_io_safety { ($($item:item)*) => { $( - #[cfg(feature = "io-safety")] + #[cfg(feature = "io_safety")] $item )* }