- = do -- we don't want to be fooled by any modules lying around in the current
- -- directory when we compile these code fragments, so set the import
- -- path to be empty while we compile them.
- dflags <- GHC.getSessionDynFlags session
- GHC.setSessionDynFlags session dflags{importPaths=[]}
-
- maybe_hval <- GHC.compileExpr session no_buf_cmd
-
- case maybe_hval of
- Just hval -> writeIORef turn_off_buffering (unsafeCoerce# hval :: IO ())
- other -> panic "interactiveUI:setBuffering"
-
- maybe_hval <- GHC.compileExpr session flush_cmd
- case maybe_hval of
- Just hval -> writeIORef flush_interp (unsafeCoerce# hval :: IO ())
- _ -> panic "interactiveUI:flush"
-
- GHC.setSessionDynFlags session dflags
- GHC.workingDirectoryChanged session
+ = do -- make sure these are linked
+ mb_hval1 <- GHC.compileExpr session "System.IO.stdout"
+ mb_hval2 <- GHC.compileExpr session "System.IO.stderr"
+ mb_hval3 <- GHC.compileExpr session "System.IO.stdin"
+ when (any isNothing [mb_hval1,mb_hval2,mb_hval3]) $
+ panic "interactiveUI:setBuffering"
+
+ -- ToDo: we should really look up these names properly, but
+ -- it's a fiddle and not all the bits are exposed via the GHC
+ -- interface.
+ mb_stdin_ptr <- ObjLink.lookupSymbol "base_GHCziHandle_stdin_closure"
+ mb_stdout_ptr <- ObjLink.lookupSymbol "base_GHCziHandle_stdout_closure"
+ mb_stderr_ptr <- ObjLink.lookupSymbol "base_GHCziHandle_stderr_closure"
+
+ let f ref (Just ptr) = writeIORef ref ptr
+ f ref Nothing = panic "interactiveUI:setBuffering2"
+ zipWithM f [stdin_ptr,stdout_ptr,stderr_ptr]
+ [mb_stdin_ptr,mb_stdout_ptr,mb_stderr_ptr]