-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consistently present absent stdio handles on Windows as NULL handles. #93263
Merged
bors
merged 3 commits into
rust-lang:master
from
sunfishcode:sunfishcode/detatched-console-handle
Mar 19, 2022
+100
−16
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, they are totally different types. No one would try to pass
io::RawHandle
whereio::RawSocket
is expected or where a process handle is expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Windows, the current process handle, as returned by
GetCurrentProcess
has typeHANDLE
, akaio::RawHandle
here, which is the same as the return type of eg.CreateFileW
.SOCKET
, akaio::RawSocket
here, on the other hand, is a different type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And so does a dozens of other types that are also an alias (or a newtype if compiled with
-DSTRICT
) ofHANDLE
: https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-typesSo, in fact it should be a newtype in Rust as well.
Okay, to be more formal: while both
GetCurrentProcess
andCreateFile
(andCreateEvent
, etc) have the same types (HANDLE
), in fact they are different handle types and no one familiar with winapi would try to use them interchangeably.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the types linked there using
HANDLE
are so different that they don't even useCloseHandle
. We already do document that it's not valid to useOwnedHandle
/BorrowedHandle
to hold those kinds of handles.Beyond that though,
OwnedHandle
,BorrowedHandle
, andAsHandle
are intended to be used with both file handles and process handles, for three reasons:RawHandle
/AsRawHandle
/IntoRawHandle
types and traits for both processes and files, so it's consistent with existing APIs in RustCloseHandle
,GetHandleInformation
,SetHandleInformation
,DuplicateHandle
, and others, so they may be different, but they're not completely different.std::fs::File
for file(-like) handles, andstd::process::Child
for process handles, and these are what most Rust code uses most of the time, so it isn't as important to make a static type distinction at theOwnedHandle
/etc. level.