diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-10-20 10:10:34 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-10-20 10:10:34 (GMT) |
commit | 6453a55538a3e3af1fbf3ae0b905988967a2200a (patch) | |
tree | edef1654a0be8eae28d5745f1b68ccbf13712007 /macosx/tkMacOSXInit.c | |
parent | 688d1318a11f09dd8b0300bf67ac783abe1b85d4 (diff) | |
download | tk-6453a55538a3e3af1fbf3ae0b905988967a2200a.zip tk-6453a55538a3e3af1fbf3ae0b905988967a2200a.tar.gz tk-6453a55538a3e3af1fbf3ae0b905988967a2200a.tar.bz2 |
Proposed fix for [c2483bfe4b]: tk fontchooser on macOS can automatically open on startup, can lead to crashes. Which also works for Tcl 8.7 and 9.0
Diffstat (limited to 'macosx/tkMacOSXInit.c')
-rw-r--r-- | macosx/tkMacOSXInit.c | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index 0e7dfe4..1323333 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -294,26 +294,33 @@ static void closePanels( * correctly for all termination scenarios. */ +#if !defined(USE_SYSTEM_EXIT) +static Bool doCleanupFromExit = NO; + +int TkMacOSXIsLaunched(void) { + return doCleanupFromExit == YES; +} + TCL_NORETURN void TkMacOSXExitProc( - ClientData clientdata) + void *clientdata) { - closePanels(); - - /* - * Make sure we don't get called again. This can happen, e.g. with - * fossil diff -tk. - */ - - Tcl_SetExitProc(NULL); + Bool doCleanup = doCleanupFromExit; + if (doCleanupFromExit) { + doCleanupFromExit = NO; /* prevent possible recursive call. */ + closePanels(); + } /* * Tcl_Exit does not call Tcl_Finalize if there is an exit proc installed. */ Tcl_Finalize(); - [(TKApplication *)NSApp superTerminate:nil]; /* Should not return. */ + if (doCleanup == YES) { + [(TKApplication *)NSApp superTerminate:nil]; /* Should not return. */ + } exit((int)clientdata); /* Convince the compiler that we don't return. */ } +#endif /* * This signal handler is installed for the SIGINT, SIGHUP and SIGTERM signals @@ -326,6 +333,8 @@ TCL_NORETURN void TkMacOSXExitProc( */ static void TkMacOSXSignalHandler(int signal) { + (void)signal; + Tcl_Exit(1); } @@ -343,7 +352,6 @@ TkpInit( if (!initialized) { struct stat st; Bool shouldOpenConsole = NO; - Bool isLaunched = NO; Bool stdinIsNullish = (!isatty(0) && (fstat(0, &st) || (S_ISCHR(st.st_mode) && st.st_blocks == 0))); @@ -443,7 +451,9 @@ TkpInit( Tcl_SetVar2(interp, "tcl_interactive", NULL, "1", TCL_GLOBAL_ONLY); } - isLaunched = YES; +#if !defined(USE_SYSTEM_EXIT) + doCleanupFromExit = YES; +#endif shouldOpenConsole = YES; } if (shouldOpenConsole) { @@ -466,7 +476,9 @@ TkpInit( FILE *null = fopen("/dev/null", "w"); dup2(fileno(null), STDOUT_FILENO); dup2(fileno(null), STDERR_FILENO); - isLaunched = YES; +#if !defined(USE_SYSTEM_EXIT) + doCleanupFromExit = YES; +#endif } /* @@ -513,11 +525,8 @@ TkpInit( # if !defined(USE_SYSTEM_EXIT) - if (isLaunched || (isatty(0) && isatty(1))) { - Tcl_ExitProc *prevExitProc = Tcl_SetExitProc(TkMacOSXExitProc); - if (prevExitProc) { - Tcl_SetExitProc((TCL_NORETURN Tcl_ExitProc *)prevExitProc); - } + if ((isatty(0) && isatty(1))) { + doCleanupFromExit = YES; } # endif |