-
Notifications
You must be signed in to change notification settings - Fork 5
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
prevent crash for WinIO in GHC 9+ #26
base: master
Are you sure you want to change the base?
Conversation
What is the magic incantation to test this? I tried these
but I always get
Adding
Yes, please! |
Indeed this is very confusing. I am using Regarding the test, I did not touch it because I was a bit confused. I don't see the difference between the current two test suites. It looks to me that they are using the same source files, but in different manners (by depending on the library or directly adding the relevant module as part of the test). (From the commit history I see those two once were different, but it seems later commits made them essentially the same.) Another thing to note: the implementation in this PR cannot deal with file handles, so the following entry in the current test-suite actually fails: Lines 18 to 26 in 1545584
Therefore this one should be made conditional. It should be disabled for the combination GHC 9+, Windows, and --io-manager=native . Currently the CI does not involve testing on Windows; I will look into the configuration to see what is the best way to add this combination.
|
Thanks for the hint with
|
Sorry, it turns out that my implementation does not actually prevent writing to Now the only thing this PR does is to prevent crash from the unsupported EDIT: I see the log you posted, and tried using
And please feel free to close this PR if you prefer making the error explicit and have downstream programs fix the real problem. |
In general, I prefer crashes over error-swallowing. So atm I am not inclined to merge this. Thanks for your investigation! I linked you PR upstream: https://gitlab.haskell.org/ghc/ghc/-/issues/22146#note_454605 |
Understood. It turns out that the native IO manager might also have other bugs (see for example commercialhaskell/stack#5851 (comment)), so the problem is not stuck here anyway.
Actually it is queried. The import of |
Ah, thanks for the explanation! |
As reported in #25,
hSilence
etc. currently fail with--io-manager=native
on Windows. According to GHC issue #22146, thehDuplicateTo
API is not supported for the new IO manager (which I believe will become the default for future GHC), and thereforehSilence
etc. need some patch to avoid crashing with the new IO manager on Windows.I do not know a workaround for hijacking an existing normal file handle, but for the common use case (to silence the standard handles
stdin
/stdout
/stderr
), I figured out a workaround. I useSetStdHandle
to overwrite and recover the handle, and useCreateFile
to get back the console handle. Please refer to the linked Microsoft documentation for details.This PR does not change the behaviour for GHC 8 and prior, nor GHC 9+ on native POSIX systems (Linux, macOS, etc.) or on Windows but with
--io-manager=legacy
(the default). In other words, the only combination that gets affected is GHC 9+ on Windows with--io-manager=native
, for which the previous behaviour was to crash the whole program. The new behaviour correctly takes care of the three standard handles, but does nothing for normal file handles (without crashing).I have tested the implementation on my local PC (GHC 9.0.2, Windows 11), and confirmed it works as intended. However, perhaps we should also add a test in the repo so that it could be verified in CI.