wincolor: Re-fetch the console on all calls #523
Merged
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.
The primary motivation for this commit was rust-lang/cargo#4189 where dropping a
wincolor::Console
would callCloseHandle
to close the console handle. Cargocreates a few
Console
instances so it ended up closing stdout a littleearlier as intended!
The
GetStdHandle
function returns handles I believe aren't intended to beclosed (as there's no refcounting). I believe libstd doesn't close these
handles.
This commit also moves to calling
GetStdHandle
on demand which libstd changedto doing so recently as well, preventing caching of stale handles that change
over time with calls to
SetStdHandle
.