Skip to content

Commit

Permalink
Qualify stdout/stderr references and handle operations.
Browse files Browse the repository at this point in the history
Fixes #201.
  • Loading branch information
quasicomputational committed Sep 30, 2020
1 parent c459b35 commit e184a15
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Unreleased
- Don't use unqualified references to `stderr` or `stdout` which may collide with definitions in user code. (#201)

Changes in 0.17
- #266:
- doctest now annotates its internal marker string as a `String`, to prevent misbehaviour in `OverloadedStrings` environments. This has a theoretical chance of breakage; if you're affected, please open an issue.
Expand Down
14 changes: 7 additions & 7 deletions ghci-wrapper/src/Language/Haskell/GhciWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ new Config{..} args_ = do
setMode stdin_
setMode stdout_
let interpreter = Interpreter {hIn = stdin_, hOut = stdout_, process = processHandle}
_ <- eval interpreter "import System.IO"
_ <- eval interpreter "import GHC.IO.Handle"
_ <- eval interpreter "import qualified System.IO"
_ <- eval interpreter "import qualified GHC.IO.Handle"
-- The buffering of stdout and stderr is NoBuffering
_ <- eval interpreter "hDuplicateTo stdout stderr"
_ <- eval interpreter "GHC.IO.Handle.hDuplicateTo System.IO.stdout System.IO.stderr"
-- Now the buffering of stderr is BlockBuffering Nothing
-- In this situation, GHC 7.7 does not flush the buffer even when
-- error happens.
_ <- eval interpreter "hSetBuffering stdout LineBuffering"
_ <- eval interpreter "hSetBuffering stderr LineBuffering"
_ <- eval interpreter "GHC.IO.Handle.hSetBuffering System.IO.stdout GHC.IO.Handle.LineBuffering"
_ <- eval interpreter "GHC.IO.Handle.hSetBuffering System.IO.stderr GHC.IO.Handle.LineBuffering"

-- this is required on systems that don't use utf8 as default encoding (e.g.
-- Windows)
_ <- eval interpreter "hSetEncoding stdout utf8"
_ <- eval interpreter "hSetEncoding stderr utf8"
_ <- eval interpreter "GHC.IO.Handle.hSetEncoding System.IO.stdout GHC.IO.Handle.utf8"

This comment has been minimized.

Copy link
@andreasabel

andreasabel Feb 27, 2021

Collaborator

See #292. This might be a regression in 0.18. It should be GHC.IO.Encoding.utf8. Appearently, we don't have a test case for that.

_ <- eval interpreter "GHC.IO.Handle.hSetEncoding System.IO.stderr GHC.IO.Handle.utf8"

_ <- eval interpreter ":m - System.IO"
_ <- eval interpreter ":m - GHC.IO.Handle"
Expand Down
11 changes: 11 additions & 0 deletions test/integration/local-stderr-binding/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module A where

stderr :: Bool
stderr = True

stdout :: String
stdout = "hello"

-- |
-- >>> 3 + 3
-- 6
10 changes: 10 additions & 0 deletions test/integration/system-io-imported/A.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module A where

import System.IO

-- ghci-wrapper needs to poke around with System.IO itself, and unloads the module once it's done. Test to make sure legitimate uses of System.IO don't get lost in the wash.

-- |
-- >>> ReadMode
-- ReadMode

0 comments on commit e184a15

Please sign in to comment.