1
Fork 0

Don't force include Windows goop when documenting

This commit is contained in:
Chris Denton 2023-05-09 19:34:01 +01:00
parent 3a37c2f052
commit d076607983
No known key found for this signature in database
GPG key ID: 713472F2F45627DE
4 changed files with 40 additions and 59 deletions

View file

@ -9,7 +9,7 @@ use crate::io;
use crate::marker::PhantomData; use crate::marker::PhantomData;
use crate::mem::forget; use crate::mem::forget;
use crate::ptr; use crate::ptr;
use crate::sys::c; use crate::sys;
use crate::sys::cvt; use crate::sys::cvt;
use crate::sys_common::{AsInner, FromInner, IntoInner}; use crate::sys_common::{AsInner, FromInner, IntoInner};
@ -190,14 +190,14 @@ impl BorrowedHandle<'_> {
/// object as the existing `BorrowedHandle` instance. /// object as the existing `BorrowedHandle` instance.
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedHandle> { pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedHandle> {
self.duplicate(0, false, c::DUPLICATE_SAME_ACCESS) self.duplicate(0, false, sys::c::DUPLICATE_SAME_ACCESS)
} }
pub(crate) fn duplicate( pub(crate) fn duplicate(
&self, &self,
access: c::DWORD, access: u32,
inherit: bool, inherit: bool,
options: c::DWORD, options: u32,
) -> io::Result<OwnedHandle> { ) -> io::Result<OwnedHandle> {
let handle = self.as_raw_handle(); let handle = self.as_raw_handle();
@ -211,14 +211,14 @@ impl BorrowedHandle<'_> {
let mut ret = ptr::null_mut(); let mut ret = ptr::null_mut();
cvt(unsafe { cvt(unsafe {
let cur_proc = c::GetCurrentProcess(); let cur_proc = sys::c::GetCurrentProcess();
c::DuplicateHandle( sys::c::DuplicateHandle(
cur_proc, cur_proc,
handle, handle,
cur_proc, cur_proc,
&mut ret, &mut ret,
access, access,
inherit as c::BOOL, inherit as sys::c::BOOL,
options, options,
) )
})?; })?;
@ -233,7 +233,7 @@ impl TryFrom<HandleOrInvalid> for OwnedHandle {
#[inline] #[inline]
fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError> { fn try_from(handle_or_invalid: HandleOrInvalid) -> Result<Self, InvalidHandleError> {
let owned_handle = handle_or_invalid.0; let owned_handle = handle_or_invalid.0;
if owned_handle.handle == c::INVALID_HANDLE_VALUE { if owned_handle.handle == sys::c::INVALID_HANDLE_VALUE {
// Don't call `CloseHandle`; it'd be harmless, except that it could // Don't call `CloseHandle`; it'd be harmless, except that it could
// overwrite the `GetLastError` error. // overwrite the `GetLastError` error.
forget(owned_handle); forget(owned_handle);
@ -365,7 +365,7 @@ impl Drop for OwnedHandle {
#[inline] #[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = c::CloseHandle(self.handle); let _ = sys::c::CloseHandle(self.handle);
} }
} }
} }

View file

@ -11,7 +11,6 @@ use crate::os::windows::io::{OwnedHandle, OwnedSocket};
use crate::os::windows::raw; use crate::os::windows::raw;
use crate::ptr; use crate::ptr;
use crate::sys; use crate::sys;
use crate::sys::c;
use crate::sys_common::{self, AsInner, FromInner, IntoInner}; use crate::sys_common::{self, AsInner, FromInner, IntoInner};
/// Raw HANDLEs. /// Raw HANDLEs.
@ -104,42 +103,42 @@ impl AsRawHandle for fs::File {
#[stable(feature = "asraw_stdio", since = "1.21.0")] #[stable(feature = "asraw_stdio", since = "1.21.0")]
impl AsRawHandle for io::Stdin { impl AsRawHandle for io::Stdin {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_INPUT_HANDLE) as RawHandle })
} }
} }
#[stable(feature = "asraw_stdio", since = "1.21.0")] #[stable(feature = "asraw_stdio", since = "1.21.0")]
impl AsRawHandle for io::Stdout { impl AsRawHandle for io::Stdout {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_OUTPUT_HANDLE) as RawHandle })
} }
} }
#[stable(feature = "asraw_stdio", since = "1.21.0")] #[stable(feature = "asraw_stdio", since = "1.21.0")]
impl AsRawHandle for io::Stderr { impl AsRawHandle for io::Stderr {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_ERROR_HANDLE) as RawHandle })
} }
} }
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")] #[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
impl<'a> AsRawHandle for io::StdinLock<'a> { impl<'a> AsRawHandle for io::StdinLock<'a> {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_INPUT_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_INPUT_HANDLE) as RawHandle })
} }
} }
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")] #[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
impl<'a> AsRawHandle for io::StdoutLock<'a> { impl<'a> AsRawHandle for io::StdoutLock<'a> {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_OUTPUT_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_OUTPUT_HANDLE) as RawHandle })
} }
} }
#[stable(feature = "asraw_stdio_locks", since = "1.35.0")] #[stable(feature = "asraw_stdio_locks", since = "1.35.0")]
impl<'a> AsRawHandle for io::StderrLock<'a> { impl<'a> AsRawHandle for io::StderrLock<'a> {
fn as_raw_handle(&self) -> RawHandle { fn as_raw_handle(&self) -> RawHandle {
stdio_handle(unsafe { c::GetStdHandle(c::STD_ERROR_HANDLE) as RawHandle }) stdio_handle(unsafe { sys::c::GetStdHandle(sys::c::STD_ERROR_HANDLE) as RawHandle })
} }
} }
@ -152,14 +151,14 @@ fn stdio_handle(raw: RawHandle) -> RawHandle {
// console. In that case, return null to the user, which is consistent // console. In that case, return null to the user, which is consistent
// with what they'd get in the parent, and which avoids the problem that // with what they'd get in the parent, and which avoids the problem that
// `INVALID_HANDLE_VALUE` aliases the current process handle. // `INVALID_HANDLE_VALUE` aliases the current process handle.
if raw == c::INVALID_HANDLE_VALUE { ptr::null_mut() } else { raw } if raw == sys::c::INVALID_HANDLE_VALUE { ptr::null_mut() } else { raw }
} }
#[stable(feature = "from_raw_os", since = "1.1.0")] #[stable(feature = "from_raw_os", since = "1.1.0")]
impl FromRawHandle for fs::File { impl FromRawHandle for fs::File {
#[inline] #[inline]
unsafe fn from_raw_handle(handle: RawHandle) -> fs::File { unsafe fn from_raw_handle(handle: RawHandle) -> fs::File {
let handle = handle as c::HANDLE; let handle = handle as sys::c::HANDLE;
fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner( fs::File::from_inner(sys::fs::File::from_inner(FromInner::from_inner(
OwnedHandle::from_raw_handle(handle), OwnedHandle::from_raw_handle(handle),
))) )))

View file

@ -9,7 +9,6 @@ use crate::marker::PhantomData;
use crate::mem; use crate::mem;
use crate::mem::forget; use crate::mem::forget;
use crate::sys; use crate::sys;
use crate::sys::c;
#[cfg(not(target_vendor = "uwp"))] #[cfg(not(target_vendor = "uwp"))]
use crate::sys::cvt; use crate::sys::cvt;
@ -76,7 +75,7 @@ impl BorrowedSocket<'_> {
#[rustc_const_stable(feature = "io_safety", since = "1.63.0")] #[rustc_const_stable(feature = "io_safety", since = "1.63.0")]
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
pub const unsafe fn borrow_raw(socket: RawSocket) -> Self { pub const unsafe fn borrow_raw(socket: RawSocket) -> Self {
assert!(socket != c::INVALID_SOCKET as RawSocket); assert!(socket != sys::c::INVALID_SOCKET as RawSocket);
Self { socket, _phantom: PhantomData } Self { socket, _phantom: PhantomData }
} }
} }
@ -94,7 +93,11 @@ impl OwnedSocket {
#[cfg(not(target_vendor = "uwp"))] #[cfg(not(target_vendor = "uwp"))]
pub(crate) fn set_no_inherit(&self) -> io::Result<()> { pub(crate) fn set_no_inherit(&self) -> io::Result<()> {
cvt(unsafe { cvt(unsafe {
c::SetHandleInformation(self.as_raw_socket() as c::HANDLE, c::HANDLE_FLAG_INHERIT, 0) sys::c::SetHandleInformation(
self.as_raw_socket() as sys::c::HANDLE,
sys::c::HANDLE_FLAG_INHERIT,
0,
)
}) })
.map(drop) .map(drop)
} }
@ -110,43 +113,47 @@ impl BorrowedSocket<'_> {
/// object as the existing `BorrowedSocket` instance. /// object as the existing `BorrowedSocket` instance.
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> io::Result<OwnedSocket> { pub fn try_clone_to_owned(&self) -> io::Result<OwnedSocket> {
let mut info = unsafe { mem::zeroed::<c::WSAPROTOCOL_INFOW>() }; let mut info = unsafe { mem::zeroed::<sys::c::WSAPROTOCOL_INFOW>() };
let result = unsafe { let result = unsafe {
c::WSADuplicateSocketW(self.as_raw_socket(), c::GetCurrentProcessId(), &mut info) sys::c::WSADuplicateSocketW(
self.as_raw_socket(),
sys::c::GetCurrentProcessId(),
&mut info,
)
}; };
sys::net::cvt(result)?; sys::net::cvt(result)?;
let socket = unsafe { let socket = unsafe {
c::WSASocketW( sys::c::WSASocketW(
info.iAddressFamily, info.iAddressFamily,
info.iSocketType, info.iSocketType,
info.iProtocol, info.iProtocol,
&mut info, &mut info,
0, 0,
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT, sys::c::WSA_FLAG_OVERLAPPED | sys::c::WSA_FLAG_NO_HANDLE_INHERIT,
) )
}; };
if socket != c::INVALID_SOCKET { if socket != sys::c::INVALID_SOCKET {
unsafe { Ok(OwnedSocket::from_raw_socket(socket)) } unsafe { Ok(OwnedSocket::from_raw_socket(socket)) }
} else { } else {
let error = unsafe { c::WSAGetLastError() }; let error = unsafe { sys::c::WSAGetLastError() };
if error != c::WSAEPROTOTYPE && error != c::WSAEINVAL { if error != sys::c::WSAEPROTOTYPE && error != sys::c::WSAEINVAL {
return Err(io::Error::from_raw_os_error(error)); return Err(io::Error::from_raw_os_error(error));
} }
let socket = unsafe { let socket = unsafe {
c::WSASocketW( sys::c::WSASocketW(
info.iAddressFamily, info.iAddressFamily,
info.iSocketType, info.iSocketType,
info.iProtocol, info.iProtocol,
&mut info, &mut info,
0, 0,
c::WSA_FLAG_OVERLAPPED, sys::c::WSA_FLAG_OVERLAPPED,
) )
}; };
if socket == c::INVALID_SOCKET { if socket == sys::c::INVALID_SOCKET {
return Err(last_error()); return Err(last_error());
} }
@ -161,7 +168,7 @@ impl BorrowedSocket<'_> {
/// Returns the last error from the Windows socket interface. /// Returns the last error from the Windows socket interface.
fn last_error() -> io::Error { fn last_error() -> io::Error {
io::Error::from_raw_os_error(unsafe { c::WSAGetLastError() }) io::Error::from_raw_os_error(unsafe { sys::c::WSAGetLastError() })
} }
#[stable(feature = "io_safety", since = "1.63.0")] #[stable(feature = "io_safety", since = "1.63.0")]
@ -194,7 +201,7 @@ impl IntoRawSocket for OwnedSocket {
impl FromRawSocket for OwnedSocket { impl FromRawSocket for OwnedSocket {
#[inline] #[inline]
unsafe fn from_raw_socket(socket: RawSocket) -> Self { unsafe fn from_raw_socket(socket: RawSocket) -> Self {
debug_assert_ne!(socket, c::INVALID_SOCKET as RawSocket); debug_assert_ne!(socket, sys::c::INVALID_SOCKET as RawSocket);
Self { socket } Self { socket }
} }
} }
@ -204,7 +211,7 @@ impl Drop for OwnedSocket {
#[inline] #[inline]
fn drop(&mut self) { fn drop(&mut self) {
unsafe { unsafe {
let _ = c::closesocket(self.socket); let _ = sys::c::closesocket(self.socket);
} }
} }
} }

View file

@ -52,31 +52,6 @@ cfg_if::cfg_if! {
} }
} }
// Import essential modules from platforms used in `std::os` when documenting.
//
// Note that on some platforms those modules don't compile
// (missing things in `libc` which is empty), so they are not included in `std::os` and can be
// omitted here as well.
#[cfg(doc)]
#[cfg(not(any(
all(target_arch = "wasm32", not(target_os = "wasi")),
all(target_vendor = "fortanix", target_env = "sgx")
)))]
cfg_if::cfg_if! {
if #[cfg(not(windows))] {
// On non-Windows platforms (aka linux/osx/etc) pull in a "minimal"
// amount of windows goop which ends up compiling
#[macro_use]
#[path = "windows/compat.rs"]
pub mod compat;
#[path = "windows/c.rs"]
pub mod c;
}
}
cfg_if::cfg_if! { cfg_if::cfg_if! {
// Fuchsia components default to full backtrace. // Fuchsia components default to full backtrace.
if #[cfg(target_os = "fuchsia")] { if #[cfg(target_os = "fuchsia")] {