-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement ExitCodeExt for Windows #97917
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
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @thomcc (rust-highfive has picked a reviewer for you, use r? to override) |
@rustbot label +T-libs-api -T-libs I don't really know what pitfalls may exist here, so punting the review to @ChrisDenton, who probably does. r? @ChrisDenton |
The idea looks reasonable to me but there is one pitfall I can think of. An exit code of 259 can be taken to mean the process has not exited yet. See I'll admit to being uncertain if this is something we want to design around. On the one hand it may be a hazard in the general case. On the other hand, there's nothing wrong with returning 259 if you're in an environment where you know it's not going to be misinterpreted. At the very least I think the docs should warn about this case. |
Also cc @yaahc. |
That's a good idea, I did not think of that. I added a warning to the documentation for this potential ambiguity. I believe we should not design around it, if one wants to request the "real" exit code they can always use |
I think you may be mistaken here and these should be marked as unstable. |
In that case, should I create a tracking issue for this feature or just repurpose the original issue as a tracking issue? |
Often "none" is used initially but in this case you can use the original issue number for now. You should probably wait for t-libs-api to sign off on the feature before making a tracking issue. |
Yes, new traits aren't insta-stable, it's only new impls of existing ones. That said, I think you're supposed to file a proposals for new APIs in https://github.com/rust-lang/libs-team now -- see here for info on the process. Here's a link to the template, I think for the you cover most of the important parts with the PR description, although you may have to move things around: https://github.com/rust-lang/libs-team/issues/new?assignees=&labels=api-change-proposal%2C+T-libs-api&template=api-change-proposal.md&title=%28My+API+Change+Proposal%29 (I hadn't realized we actually went forward with this, I think it just started this week, sorry that you have to be one of the guinea-pigs 😅). |
Ah I see, thank you for clarifying this.
I submitted a proposal right here which includes all original data from this request and more: rust-lang/libs-team#48
No problem! I understand that Rust is a large project that requires some organizational effort to manage its popularity. I'm thankful that you people take your time to review my request. |
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.
Ok, this ACP process is new but it looks like it's had the time and the libs-api team is in favour of having this in nightly. So I'm going to go ahead and approve.
@bors r+ rollup |
📌 Commit b13af73 has been approved by |
Implement ExitCodeExt for Windows Fixes rust-lang#97914 ### Motivation: On Windows it is common for applications to return `HRESULT` (`i32`) or `DWORD` (`u32`) values. These stem from COM based components ([HRESULTS](https://docs.microsoft.com/en-us/windows/win32/api/objbase/nf-objbase-coinitialize)), Win32 errors ([GetLastError](https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-getlasterror)), GUI applications ([WM_QUIT](https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-quit)) and more. The newly stabilized `ExitCode` provides an excellent fit for propagating these values, because `std::process::exit` does not run deconstructors which can result in errors. However, `ExitCode` currently only implements `From<u8> for ExitCode`, which disallows the full range of `i32`/`u32` values. This pull requests attempts to address that shortcoming by providing windows specific extensions that accept a `u32` value (which covers all possible `HRESULTS` and Win32 errors) analog to [ExitStatusExt::from_raw](https://doc.rust-lang.org/std/os/windows/process/trait.ExitStatusExt.html#tymethod.from_raw). This was also intended by the original Stabilization rust-lang#93840 (comment) as pointed out by `@eggyal` in rust-lang#97914 (comment): > Issues around platform specific representations: We resolved this issue by changing the return type of report from i32 to the opaque type ExitCode. __That way we can change the underlying representation without affecting the API, letting us offer full support for platform specific exit code APIs in the future.__ [Emphasis added] ### API ```rust /// Windows-specific extensions to [`process::ExitCode`]. /// /// This trait is sealed: it cannot be implemented outside the standard library. /// This is so that future additional methods are not breaking changes. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] pub trait ExitCodeExt: Sealed { /// Creates a new `ExitCode` from the raw underlying `u32` return value of /// a process. #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] fn from_raw(raw: u32) -> Self; } #[stable(feature = "windows_process_exit_code_from", since = "1.63.0")] impl ExitCodeExt for process::ExitCode { fn from_raw(raw: u32) -> Self { process::ExitCode::from_inner(From::from(raw)) } } ``` ### Misc I apologize in advance if I misplaced any attributes regarding stabilzation, as far as I learned traits are insta-stable so I chose to make them stable. If this is an error, please let me know and I'll correct it. I also added some additional machinery to make it work, analog to [ExitStatus](https://doc.rust-lang.org/std/process/struct.ExitStatus.html#). EDIT: Proposal: rust-lang/libs-team#48
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#97917 (Implement ExitCodeExt for Windows) - rust-lang#98844 (Reword comments and rename HIR visiting methods.) - rust-lang#98979 (interpret: use AllocRange in UninitByteAccess) - rust-lang#98986 (Fix missing word in comment) - rust-lang#98994 (replace process exit with more detailed exit in src/bootstrap/*.rs) - rust-lang#98995 (Add a test for rust-lang#80471) - rust-lang#99002 (suggest adding a derive for #[default] applied to variants) - rust-lang#99004 (Add a test for rust-lang#70408) - rust-lang#99017 (Replace boolean argument for print_where_clause with an enum to make code more clear) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fix tracking issue of Windows ExitCodeExt Tracking issue: rust-lang#111688 This was left out of the initial ExitCodeExt implementation in rust-lang#97917.
Fixes #97914
Motivation:
On Windows it is common for applications to return
HRESULT
(i32
) orDWORD
(u32
) values. These stem from COM based components (HRESULTS), Win32 errors (GetLastError), GUI applications (WM_QUIT) and more. The newly stabilizedExitCode
provides an excellent fit for propagating these values, becausestd::process::exit
does not run deconstructors which can result in errors. However,ExitCode
currently only implementsFrom<u8> for ExitCode
, which disallows the full range ofi32
/u32
values. This pull requests attempts to address that shortcoming by providing windows specific extensions that accept au32
value (which covers all possibleHRESULTS
and Win32 errors) analog to ExitStatusExt::from_raw.This was also intended by the original Stabilization #93840 (comment) as pointed out by @eggyal in #97914 (comment):
[Emphasis added]
API
Misc
I apologize in advance if I misplaced any attributes regarding stabilzation, as far as I learned traits are insta-stable so I chose to make them stable. If this is an error, please let me know and I'll correct it. I also added some additional machinery to make it work, analog to ExitStatus.
EDIT: Proposal: rust-lang/libs-team#48