Skip to content
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

Clarify what values BorrowedHandle, OwnedHandle etc. can hold. #96932

Merged

Conversation

sunfishcode
Copy link
Member

Reword the documentation to clarify that when BorrowedHandle, OwnedHandle, or HandleOrNull hold the value -1, it always means the current process handle, and not INVALID_HANDLE_VALUE.

-1 should only mean INVALID_HANDLE_VALUE after a call to a function documented to return that to report errors, which should lead I/O functions to produce errors rather than succeeding and producing OwnedHandle or BorrowedHandle values. So if a consumer of an OwnedHandle or BorrowedHandle ever sees them holding a -1, it should always mean the current process handle.

Clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull`
hold the value `-1`, it always means the current process handle, and not
`INVALID_HANDLE_VALUE`.
@sunfishcode sunfishcode added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label May 11, 2022
@rust-highfive
Copy link
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with r? rust-lang/libs-api @rustbot label +T-libs-api -T-libs to request review from a libs-api team reviewer. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 11, 2022
/// 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 [`OwnedHandle`] may hold, except `NULL`. It may
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence sounds like this type cannot hold NULL, but it's the other way around (the type can hold NULL as the sentry value).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I've now reworded this.

sunfishcode added a commit to sunfishcode/io-lifetimes that referenced this pull request May 11, 2022
@joshtriplett
Copy link
Member

Seems reasonable. Are there no other circumstances in which such a handle might ever hold -1? Is there no way to end up with one yourself, if constructed that way rather than returned from a Windows API?

@sunfishcode
Copy link
Member Author

Seems reasonable. Are there no other circumstances in which such a handle might ever hold -1? Is there no way to end up with one yourself, if constructed that way rather than returned from a Windows API?

The value of -1 is documented here, though it does also say that in theory the current process handle could have a different value in future OS versions. I've now added a patch to change the wording to reflect that OwnedHandle etc. interpret -1 as a valid handle, with the current process handle being an example of such a valid handle.

@rust-log-analyzer

This comment has been minimized.

@ChrisDenton
Copy link
Member

I'd only add that all valid handle values should originally come from the Windows API in one way or another. Like pointers they shouldn't be created out of thin air. This goes for pseudo-handles too. As mentioned above, even though they may have a known value this value isn't actually guaranteed.

@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 12, 2022

📌 Commit 275812a has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 12, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 12, 2022
…rrowed-handle, r=joshtriplett

Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.

Reword the documentation to clarify that when `BorrowedHandle`, `OwnedHandle`, or `HandleOrNull` hold the value `-1`, it always means the current process handle, and not `INVALID_HANDLE_VALUE`.

`-1` should only mean `INVALID_HANDLE_VALUE` after a call to a function documented to return that to report errors, which should lead I/O functions to produce errors rather than succeeding and producing `OwnedHandle` or `BorrowedHandle` values. So if a consumer of an `OwnedHandle` or `BorrowedHandle` ever sees them holding a `-1`, it should always mean the current process handle.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 13, 2022
…askrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#96932 (Clarify what values `BorrowedHandle`, `OwnedHandle` etc. can hold.)
 - rust-lang#96948 (Add test of matches macro for trailing commas)
 - rust-lang#96988 (Fix platform support links.)
 - rust-lang#96989 (Be more precise than DefPathData::Misc.)
 - rust-lang#96993 (rustdoc: fix GUI crash when searching for magic JS property values)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit f38b7ff into rust-lang:master May 13, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 13, 2022
@sunfishcode sunfishcode deleted the sunfishcode/document-borrowed-handle branch May 13, 2022 13:50
sunfishcode added a commit to sunfishcode/io-lifetimes that referenced this pull request May 13, 2022
* Clarify what values BorrowedHandle, OwnedHandle etc. can hold.

This ports the documentation updates from rust-lang/rust#96932.

* Relax the wording about the meaning of -1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants