From 66797dc0cdc254837e58f9c46393e6df54d36aaa Mon Sep 17 00:00:00 2001 From: simonmar Date: Wed, 26 Jan 2005 12:58:09 +0000 Subject: [PATCH] [project @ 2005-01-26 12:58:09 by simonmar] 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 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ghc/compiler/ghci/InteractiveUI.hs b/ghc/compiler/ghci/InteractiveUI.hs index c6d650e..35f9814 100644 --- a/ghc/compiler/ghci/InteractiveUI.hs +++ b/ghc/compiler/ghci/InteractiveUI.hs @@ -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 -- 1.7.10.4