[project @ 2005-01-26 12:58:09 by simonmar]
authorsimonmar <unknown>
Wed, 26 Jan 2005 12:58:09 +0000 (12:58 +0000)
committersimonmar <unknown>
Wed, 26 Jan 2005 12:58:09 +0000 (12:58 +0000)
fileLoop: catch InvalidArgument and behave as for EOF (i.e. terminate
the session).  This means that the user can close stdin to end a GHCi
session, but it also means that the tests that run programs which use
getContents inside GHCi won't crash because stdin has been closed.

ghc/compiler/ghci/InteractiveUI.hs

index c6d650e..35f9814 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -#include "Linker.h" #-}
 -----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.183 2005/01/18 12:18:19 simonpj Exp $
+-- $Id: InteractiveUI.hs,v 1.184 2005/01/26 12:58:09 simonmar Exp $
 --
 -- GHC Interactive User Interface
 --
@@ -68,6 +68,7 @@ import Control.Monad as Monad
 import Foreign.StablePtr       ( newStablePtr )
 
 import GHC.Exts                ( unsafeCoerce# )
+import GHC.IOBase      ( IOErrorType(InvalidArgument) )
 
 import Data.IORef      ( IORef, newIORef, readIORef, writeIORef )
 
@@ -308,8 +309,14 @@ fileLoop hdl prompt = do
    when prompt (io (putStr (mkPrompt mod imports)))
    l <- io (IO.try (hGetLine hdl))
    case l of
-       Left e | isEOFError e -> return ()
-              | otherwise    -> io (ioError e)
+       Left e | isEOFError e              -> return ()
+              | InvalidArgument <- etype  -> return ()
+              | otherwise                 -> io (ioError e)
+               where etype = ioeGetErrorType e
+               -- treat InvalidArgument in the same way as EOF:
+               -- this can happen if the user closed stdin, or
+               -- perhaps did getContents which closes stdin at
+               -- EOF.
        Right l -> 
          case remove_spaces l of
            "" -> fileLoop hdl prompt