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

prevent crash for WinIO in GHC 9+ #26

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 3 additions & 32 deletions silently.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,50 +63,21 @@ Library
ghc-options:
-Wcompat

-- This tests the platform specific implementation.
--
-- NOTE: Cabal 1.10 can not deal with conditional (== if-else) options. This
-- is why we depend on silently to test the platform specific implementation.
--
-- As a consequence we can not use Hspec for testing, as this would result in
-- depending on two different versions of silently at the same time!
test-suite spec-specific
type:
exitcode-stdio-1.0
hs-source-dirs:
test
main-is:
Spec.hs
default-language:
Haskell98
ghc-options:
-Wall -threaded
build-depends:
base
, silently
, directory
, nanospec
, temporary

-- This tests the generic implementation, that should work on all platforms.
test-suite spec-generic
type:
exitcode-stdio-1.0
hs-source-dirs:
src
, test
test
main-is:
Spec.hs
default-language:
Haskell98
ghc-options:
-Wall -threaded
other-modules:
System.IO.Silently

-Wall -threaded -rtsopts
build-depends:
base
, deepseq
, silently
, directory
, nanospec
, temporary
14 changes: 13 additions & 1 deletion src/System/IO/Silently.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import System.IO
, openFile, openTempFile, stdout
)

#if defined(WINDOWS) && __GLASGOW_HASKELL__ >= 900
import GHC.IO.SubSystem ((<!>))
#endif

mNullDevice :: Maybe FilePath
#ifdef WINDOWS
mNullDevice = Just "\\\\.\\NUL"
Expand Down Expand Up @@ -110,7 +114,15 @@ hCapture handles action = withTempFile "capture" prepareAndRun
go (h:hs) = goBracket go tmpHandle h hs

goBracket :: ([Handle] -> IO a) -> Handle -> Handle -> [Handle] -> IO a
goBracket go tmpHandle h hs = do
#if defined(WINDOWS) && __GLASGOW_HASKELL__ >= 900
goBracket = goBracketPosix <!> giveUp
where giveUp go _ _ _ = go []
#else
goBracket = goBracketPosix
#endif

goBracketPosix :: ([Handle] -> IO a) -> Handle -> Handle -> [Handle] -> IO a
goBracketPosix go tmpHandle h hs = do
buffering <- hGetBuffering h
let redirect = do
old <- hDuplicate h
Expand Down