Commit 2babc2a5 authored by Simon Marlow's avatar Simon Marlow

Flush stdout and stderr during hs_exit() (#5594)

Ensures that these handles are flushed even when the RTS is being used
as a library, with no main.

Needs a corresponding change to libraries/base.
parent 81e29e42
......@@ -47,6 +47,8 @@ PRELUDE_CLOSURE(base_GHCziConcziSync_runSparks_closure);
PRELUDE_CLOSURE(base_GHCziConcziIO_ensureIOManagerIsRunning_closure);
PRELUDE_CLOSURE(base_GHCziConcziSignal_runHandlers_closure);
PRELUDE_CLOSURE(base_GHCziTopHandler_flushStdHandles_closure);
PRELUDE_INFO(ghczmprim_GHCziTypes_Czh_static_info);
PRELUDE_INFO(ghczmprim_GHCziTypes_Izh_static_info);
PRELUDE_INFO(ghczmprim_GHCziTypes_Fzh_static_info);
......
......@@ -69,6 +69,8 @@ void exitLinker( void ); // there is no Linker.h file to include
// Count of how many outstanding hs_init()s there have been.
static int hs_init_count = 0;
static void flushStdHandles(void);
/* -----------------------------------------------------------------------------
Initialise floating point unit on x86 (currently disabled; See Note
[x86 Floating point precision] in compiler/nativeGen/X86/Instr.hs)
......@@ -296,6 +298,8 @@ hs_exit_(rtsBool wait_foreign)
OnExitHook();
flushStdHandles();
// sanity check
#if defined(DEBUG)
checkFPUStack();
......@@ -407,6 +411,17 @@ hs_exit_(rtsBool wait_foreign)
freeRtsArgs();
}
// Flush stdout and stderr. We do this during shutdown so that it
// happens even when the RTS is being used as a library, without a
// main (#5594)
static void flushStdHandles(void)
{
Capability *cap;
cap = rts_lock();
rts_evalIO(cap, &base_GHCziTopHandler_flushStdHandles_closure, NULL);
rts_unlock(cap);
}
// The real hs_exit():
void
hs_exit(void)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment