From d23fcba52a5e13b6ce4bc6effbeb50c391a547ea Mon Sep 17 00:00:00 2001 From: Simon Marlow <marlowsd@gmail.com> Date: Fri, 12 Aug 2011 14:26:34 +0100 Subject: [PATCH] make shutdownHaskellAndExit() shut down the RTS and exit immediately (#5402) --- includes/RtsAPI.h | 6 +++++- rts/RtsMain.c | 2 +- rts/RtsMain.h | 3 ++- rts/RtsStartup.c | 8 +++++--- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/RtsAPI.h b/includes/RtsAPI.h index 1444dbc3c587..dc151faf071a 100644 --- a/includes/RtsAPI.h +++ b/includes/RtsAPI.h @@ -43,7 +43,11 @@ typedef struct Capability_ Capability; extern void startupHaskell ( int argc, char *argv[], void (*init_root)(void) ); extern void shutdownHaskell ( void ); -extern void shutdownHaskellAndExit ( int exitCode ); +extern void shutdownHaskellAndExit ( int exitCode ) +#if __GNUC__ >= 3 + __attribute__((__noreturn__)) +#endif + ; extern void getProgArgv ( int *argc, char **argv[] ); extern void setProgArgv ( int argc, char *argv[] ); extern void getFullProgArgv ( int *argc, char **argv[] ); diff --git a/rts/RtsMain.c b/rts/RtsMain.c index 0ed6df494c25..a822da9749f2 100644 --- a/rts/RtsMain.c +++ b/rts/RtsMain.c @@ -38,6 +38,7 @@ static StgClosure *progmain_closure; /* This will be ZCMain_main_closure */ * INTERPRETER is set */ #ifndef INTERPRETER /* Hack */ +static void real_main(void) GNUC3_ATTRIBUTE(__noreturn__); static void real_main(void) { int exit_status; @@ -112,6 +113,5 @@ int hs_main(int argc, char *argv[], StgClosure *main_closure) #if defined(mingw32_HOST_OS) END_CATCH #endif - return 0; /* not reached, but keeps gcc -Wall happy */ } # endif /* BATCH_MODE */ diff --git a/rts/RtsMain.h b/rts/RtsMain.h index 24e58199bbdf..e004480ccee2 100644 --- a/rts/RtsMain.h +++ b/rts/RtsMain.h @@ -13,6 +13,7 @@ * The entry point for Haskell programs that use a Haskell main function * -------------------------------------------------------------------------- */ -int hs_main(int argc, char *argv[], StgClosure *main_closure); +int hs_main(int argc, char *argv[], StgClosure *main_closure) + GNUC3_ATTRIBUTE(__noreturn__); #endif /* RTSMAIN_H */ diff --git a/rts/RtsStartup.c b/rts/RtsStartup.c index c115701d6ccc..6e18fba27399 100644 --- a/rts/RtsStartup.c +++ b/rts/RtsStartup.c @@ -424,12 +424,14 @@ shutdownHaskell(void) void shutdownHaskellAndExit(int n) { + // even if hs_init_count > 1, we still want to shut down the RTS + // and exit immediately (see #5402) + hs_init_count = 1; + // we're about to exit(), no need to wait for foreign calls to return. hs_exit_(rtsFalse); - if (hs_init_count == 0) { - stg_exit(n); - } + stg_exit(n); } #ifndef mingw32_HOST_OS -- GitLab