[project @ 2004-08-20 15:02:40 by simonmar]
authorsimonmar <unknown>
Fri, 20 Aug 2004 15:02:40 +0000 (15:02 +0000)
committersimonmar <unknown>
Fri, 20 Aug 2004 15:02:40 +0000 (15:02 +0000)
Hack to work around bug on Windows reported by Levent Erkok
<levent.erkok@intel.com>:

Prelude> let x=x in x
*** Exception: <<loop>>
Prelude> 3
Fail: thread blocked indefinitely

Details in the comment.

MERGE TO STABLE

ghc/compiler/ghci/InteractiveUI.hs

index 9a885ab..98b653d 100644 (file)
@@ -1,6 +1,6 @@
 {-# OPTIONS -#include "Linker.h" #-}
 -----------------------------------------------------------------------------
--- $Id: InteractiveUI.hs,v 1.174 2004/08/16 09:53:57 simonpj Exp $
+-- $Id: InteractiveUI.hs,v 1.175 2004/08/20 15:02:40 simonmar Exp $
 --
 -- GHC Interactive User Interface
 --
@@ -68,6 +68,7 @@ import System.Directory
 import System.IO as IO
 import Data.Char
 import Control.Monad as Monad
+import Foreign.StablePtr       ( newStablePtr )
 
 import GHC.Exts                ( unsafeCoerce# )
 
@@ -159,6 +160,18 @@ interactiveUI srcs maybe_expr = do
 
    cmstate <- cmInit Interactive dflags;
 
+   -- HACK! If we happen to get into an infinite loop (eg the user
+   -- types 'let x=x in x' at the prompt), then the thread will block
+   -- on a blackhole, and become unreachable during GC.  The GC will
+   -- detect that it is unreachable and send it the NonTermination
+   -- exception.  However, since the thread is unreachable, everything
+   -- it refers to might be finalized, including the standard Handles.
+   -- This sounds like a bug, but we don't have a good solution right
+   -- now.
+   newStablePtr stdin
+   newStablePtr stdout
+   newStablePtr stderr
+
    hFlush stdout
    hSetBuffering stdout NoBuffering