X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=GHC%2FTopHandler.lhs;h=8c123a228412bb58f9d80550a63a3239fd62e21b;hb=3fd4171f4de7ebe1761839a6e9a4818cf67f7def;hp=03e54632107e9a76790188ee79b83d4ae5648b06;hpb=4618e6c0c7859a3f3407e0f5eb62f1be25d2adb2;p=ghc-base.git diff --git a/GHC/TopHandler.lhs b/GHC/TopHandler.lhs index 03e5463..8c123a2 100644 --- a/GHC/TopHandler.lhs +++ b/GHC/TopHandler.lhs @@ -15,12 +15,13 @@ ----------------------------------------------------------------------------- module GHC.TopHandler ( - runIO, runNonIO, reportStackOverflow, reportError + runIO, runNonIO, reportStackOverflow, reportError ) where import Prelude import System.IO +import Control.Exception import Foreign.C.String import Foreign.Ptr @@ -28,7 +29,7 @@ import GHC.IOBase import GHC.Exception import GHC.Prim (unsafeCoerce#) --- | 'runIO' is wrapped around 'Main.main' by @TcModule@. It is also wrapped +-- | 'runIO' is wrapped around @Main.main@ by @TcModule@. It is also wrapped -- around every @foreign export@ and @foreign import \"wrapper\"@ to mop up -- any uncaught exceptions. Thus, the result of running -- 'System.Exit.exitWith' in a foreign-exported function is the same as @@ -60,11 +61,8 @@ real_handler ex = ExitException ExitSuccess -> safe_exit 0 ExitException (ExitFailure n) -> safe_exit n - Deadlock -> reportError True - "no threads to run: infinite loop or deadlock?" - - ErrorCall s -> reportError True s - other -> reportError True (showsPrec 0 other "\n") + other -> reportError True other + reportStackOverflow :: Bool -> IO a reportStackOverflow bombOut = do @@ -74,23 +72,13 @@ reportStackOverflow bombOut = do then exit 2 else return undefined -reportError :: Bool -> String -> IO a -reportError bombOut str = do - (hFlush stdout) `catchException` (\ _ -> return ()) - withCStringLen str $ \(cstr,len) -> do - writeErrString errorHdrHook cstr len - if bombOut - then exit 1 - else return undefined - -#ifndef ILX -foreign import ccall "&ErrorHdrHook" errorHdrHook :: Ptr () -#else -foreign import ccall "ErrorHdrHook" errorHdrHook :: Ptr () -#endif - -foreign import ccall unsafe "writeErrString__" - writeErrString :: Ptr () -> CString -> Int -> IO () +reportError :: Bool -> Exception -> IO a +reportError bombOut ex = do + handler <- getUncaughtExceptionHandler + handler ex + if bombOut + then exit 1 + else return undefined -- SUP: Are the hooks allowed to re-enter Haskell land? If so, remove -- the unsafe below.