ghci changing 'm' to 'g'

Simon Marlow simonmarhaskell at
Thu Nov 22 04:04:22 EST 2007

Yitzchak Gale wrote:
> Quoth InteractiveUI.runGHCi:
>   case maybe_expr of
>         Nothing ->
>           do
> #if defined(mingw32_HOST_OS)
>             -- The win32 Console API mutates the first character of
>             -- type-ahead when reading from it in a non-buffered manner. Work
>             -- around this by flushing the input buffer of type-ahead
> characters,
>             -- but only if stdin is available.
>             flushed <- io (IO.try (GHC.ConsoleHandler.flushConsole stdin))
>             case flushed of
>              Left err | isDoesNotExistError err -> return ()
>                       | otherwise -> io (ioError err)
>              Right () -> return ()
> #endif
>             -- enter the interactive loop
>             interactiveLoop is_tty show_prompt
> Could this be related somehow?

This was a hack to work around similar behaviour when starting up GHCi, and 
hence Sigbjorn's comment on #831:

"that's right; I did add a workaround in the end, see comments in 
ghci/InteractiveUI.hs:runGHCi. It's in both STABLE and HEAD; dunno if it 
scratches this particular itch though.

Notice that my workaround is only applied upon startup, not in the REPL. => 
floating the hackery inward could just save the day. "

The underlying bug is in the Windows CRT, or perhaps a deeper level.  IIRC 
it exists on a bug tracker somewhere inside Microsoft...


More information about the Glasgow-haskell-users mailing list