diff options
| author | Dan Gohman <dev@sunfishcode.online> | 2022-05-10 21:20:34 -0700 |
|---|---|---|
| committer | Dan Gohman <dev@sunfishcode.online> | 2022-05-10 21:25:48 -0700 |
| commit | 4ce68c13bfbd88df8d93da676e8424544c27321e (patch) | |
| tree | ca10238d8c6d137893ad64ee1e9320e7ca429b8e /library/std/src/os/windows | |
| parent | ecd44958e0a21110d09862ee080d95a4ca6c52f8 (diff) | |
| download | rust-4ce68c13bfbd88df8d93da676e8424544c27321e.tar.gz rust-4ce68c13bfbd88df8d93da676e8424544c27321e.zip | |
Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.
Clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull` hold the value `-1`, it always means the current process handle, and not `INVALID_HANDLE_VALUE`.
Diffstat (limited to 'library/std/src/os/windows')
| -rw-r--r-- | library/std/src/os/windows/io/handle.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/library/std/src/os/windows/io/handle.rs b/library/std/src/os/windows/io/handle.rs index 290b7f0d08a..b80ea0ac5ee 100644 --- a/library/std/src/os/windows/io/handle.rs +++ b/library/std/src/os/windows/io/handle.rs @@ -22,8 +22,9 @@ use crate::sys_common::{AsInner, FromInner, IntoInner}; /// so it can be used in FFI in places where a handle is passed as an argument, /// it is not captured or consumed. /// -/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is -/// sometimes a valid handle value. See [here] for the full story. +/// Note that it *may* have the value `-1`, which in `BorrowedFd` always +/// represents the current process handle, and not `INVALID_HANDLE_VALUE`, +/// despite the two having the same value. See [here] for the full story. /// /// And, it *may* have the value `NULL` (0), which can occur when consoles are /// detached from processes, or when `windows_subsystem` is used. @@ -45,8 +46,9 @@ pub struct BorrowedHandle<'handle> { /// /// This closes the handle on drop. /// -/// Note that it *may* have the value `INVALID_HANDLE_VALUE` (-1), which is -/// sometimes a valid handle value. See [here] for the full story. +/// Note that it *may* have the value `-1`, which in `OwnedFd` always +/// represents the current process handle, and not `INVALID_HANDLE_VALUE`, +/// despite the two having the same value. See [here] for the full story. /// /// And, it *may* have the value `NULL` (0), which can occur when consoles are /// detached from processes, or when `windows_subsystem` is used. @@ -75,11 +77,11 @@ pub struct OwnedHandle { /// `NULL`. This ensures that such FFI calls cannot start using the handle without /// checking for `NULL` first. /// -/// This type considers any value other than `NULL` to be valid, including `INVALID_HANDLE_VALUE`. -/// This is because APIs that use `NULL` as their sentry value don't treat `INVALID_HANDLE_VALUE` -/// as special. +/// This type may hold any handle value that [`OwnedFd`] may hold, except `NULL`. It may +/// hold `-1`, even though `-1` has the same value as `INVALID_HANDLE_VALUE`, because in +/// `HandleOrNull`, `-1` is interpreted to mean the current process handle. /// -/// If this holds a valid handle, it will close the handle on drop. +/// If this holds a non-null handle, it will close the handle on drop. #[repr(transparent)] #[unstable(feature = "io_safety", issue = "87074")] #[derive(Debug)] @@ -95,11 +97,14 @@ pub struct HandleOrNull(OwnedHandle); /// `INVALID_HANDLE_VALUE`. This ensures that such FFI calls cannot start using the handle without /// checking for `INVALID_HANDLE_VALUE` first. /// -/// This type considers any value other than `INVALID_HANDLE_VALUE` to be valid, including `NULL`. -/// This is because APIs that use `INVALID_HANDLE_VALUE` as their sentry value may return `NULL` -/// under `windows_subsystem = "windows"` or other situations where I/O devices are detached. +/// This type may hold any handle value that [`OwnedFd`] may hold, except `-1`. It must not +/// hold `-1`, because `-1` in `HandleOrInvalid` is interpreted to mean `INVALID_HANDLE_VALUE`. /// -/// If this holds a valid handle, it will close the handle on drop. +/// This type may hold `NULL`, because APIs that use `INVALID_HANDLE_VALUE` as their sentry value +/// may return `NULL` under `windows_subsystem = "windows"` or other situations where I/O devices +/// are detached. +/// +/// If holds a handle other than `INVALID_HANDLE_VALUE`, it will close the handle on drop. #[repr(transparent)] #[unstable(feature = "io_safety", issue = "87074")] #[derive(Debug)] |
