X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FConsoleHandler.hs;h=ed6eb2bca33fb9441cc9110a09f70d06195e0962;hb=8a37d80b44f75105c23b62f89bb7806b1c331c26;hp=7587d94e717f8bf798ca9872d6838e65c008b2a0;hpb=16875d8036c552e5920e219b972b764387971dcf;p=ghc-base.git diff --git a/GHC/ConsoleHandler.hs b/GHC/ConsoleHandler.hs index 7587d94..ed6eb2b 100644 --- a/GHC/ConsoleHandler.hs +++ b/GHC/ConsoleHandler.hs @@ -18,7 +18,6 @@ module GHC.ConsoleHandler #if !defined(mingw32_HOST_OS) && !defined(__HADDOCK__) where -import Prelude -- necessary to get dependencies right #else /* whole file */ ( Handler(..) , installHandler @@ -27,17 +26,25 @@ import Prelude -- necessary to get dependencies right ) where {- -#include "Signals.h" +#include "rts/Signals.h" -} -import Prelude -- necessary to get dependencies right - import Foreign import Foreign.C -import GHC.IOBase +import GHC.IO.FD +import GHC.IO.Exception +import GHC.IO.Handle.Types +import GHC.IO.Handle.Internals import GHC.Conc -import GHC.Handle -import Control.Exception (onException) +import Control.Concurrent.MVar +import Data.Typeable + +#ifdef mingw32_HOST_OS +import Data.Maybe +import GHC.Base +import GHC.Num +import GHC.Real +#endif data Handler = Default @@ -134,19 +141,16 @@ foreign import ccall unsafe "RtsExternal.h rts_ConsoleHandlerDone" flushConsole :: Handle -> IO () flushConsole h = - wantReadableHandle "flushConsole" h $ \ h_ -> - throwErrnoIfMinus1Retry_ "flushConsole" - (flush_console_fd (fromIntegral (haFD h_))) + wantReadableHandle_ "flushConsole" h $ \ Handle__{haDevice=dev} -> + case cast dev of + Nothing -> ioException $ + IOError (Just h) IllegalOperation "flushConsole" + "handle is not a file descriptor" Nothing Nothing + Just fd -> do + throwErrnoIfMinus1Retry_ "flushConsole" $ + flush_console_fd (fromIntegral (fdFD fd)) foreign import ccall unsafe "consUtils.h flush_input_console__" flush_console_fd :: CInt -> IO CInt --- XXX Copied from Control.Concurrent.MVar -modifyMVar :: MVar a -> (a -> IO (a,b)) -> IO b -modifyMVar m io = - block $ do - a <- takeMVar m - (a',b) <- unblock (io a) `onException` putMVar m a - putMVar m a' - return b #endif /* mingw32_HOST_OS */