From a530ba4b1bac3b501e819f8d66bdfdd81ddc2e12 Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 27 Jan 2025 15:34:17 +0000 Subject: [PATCH] Backport fix for [080a28104e] and add TK_NO_STDERR processing. --- .github/workflows/mac-build.yml | 7 +++-- macosx/tkMacOSXDialog.c | 54 +++++++++++++++++++++++++++++++-- macosx/tkMacOSXInit.c | 9 ++++++ macosx/tkMacOSXPrivate.h | 6 ++++ macosx/tkMacOSXTest.c | 7 ++++- tests/filebox.test | 10 ++++++ 6 files changed, 87 insertions(+), 6 deletions(-) diff --git a/.github/workflows/mac-build.yml b/.github/workflows/mac-build.yml index 0e5f00c85..f17c3ed4c 100644 --- a/.github/workflows/mac-build.yml +++ b/.github/workflows/mac-build.yml @@ -13,7 +13,7 @@ env: ERROR_ON_FAILURES: 1 jobs: xcode: - runs-on: macos-13 + runs-on: macos-15 defaults: run: shell: bash @@ -48,7 +48,7 @@ jobs: } - name: Run Tests run: | - make test | tee out.txt + make TK_NO_STDERR=1 test | tee out.txt nmatches=$( grep -c "Failed 0" out.txt ) if [ $nmatches -lt 4 ] then @@ -57,7 +57,7 @@ jobs: fi timeout-minutes: 30 clang: - runs-on: macos-13 + runs-on: macos-15 strategy: matrix: symbols: @@ -144,6 +144,7 @@ jobs: else function runXvfb { echo Xvfb not used, this is a --enable-aqua build + export TK_NO_STDERR=1 } fi ( runXvfb :0; make test-classic; exit $? ) | tee out-classic.txt || { diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index 8b53f97af..f6e704a21 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -37,7 +37,9 @@ static void setAllowedFileTypes( NSMutableArray *allowedTypes = [NSMutableArray array]; for (NSString *ext in extensions) { UTType *uttype = [UTType typeWithFilenameExtension: ext]; - [allowedTypes addObject:uttype]; + if (uttype) { + [allowedTypes addObject:uttype]; + } } [panel setAllowedContentTypes:allowedTypes]; } else { @@ -85,6 +87,41 @@ static filepanelFilterInfo filterInfo; static NSOpenPanel *openpanel; static NSSavePanel *savepanel; +/* + * A thread which closes the currently running modal dialog after a timeout. + */ + +@interface TKPanelMonitor: NSThread { +@private + NSTimeInterval _timeout; +} + +- (id) initWithTimeout: (NSTimeInterval) timeout; + +@end + +@implementation TKPanelMonitor: NSThread + +- (id) initWithTimeout: (NSTimeInterval) timeout { + self = [super init]; + if (self) { + _timeout = timeout; + return self; + } + return self; +} + +- (void) main +{ + [NSThread sleepForTimeInterval:_timeout]; + if ([self isCancelled]) { + [NSThread exit]; + } + [NSApp stopModalWithCode:modalCancel]; +} +@end + + static const char *const colorOptionStrings[] = { "-initialcolor", "-parent", "-title", NULL }; @@ -866,7 +903,20 @@ Tk_GetOpenFileObjCmd( parent = nil; parentIsKey = False; } - modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, multiple); + TKPanelMonitor *monitor; + if (testsAreRunning) { + /* + * We need the panel to close by itself when running tests. + */ + + monitor = [[TKPanelMonitor alloc] initWithTimeout: 1.0]; + [monitor start]; + } + modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, + multiple); + if (testsAreRunning) { + [monitor cancel]; + } if (cmdObj) { Tcl_DecrRefCount(cmdObj); } diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c index e6a68356c..ed74f7c0b 100644 --- a/macosx/tkMacOSXInit.c +++ b/macosx/tkMacOSXInit.c @@ -20,6 +20,12 @@ #include #include +/* + * This flag is set if tests are being run. + */ + +int testsAreRunning = 0; + static char tkLibPath[PATH_MAX + 1] = ""; /* @@ -594,6 +600,9 @@ TkpInit( #if defined(USE_CUSTOM_EXIT_PROC) doCleanupFromExit = YES; #endif + } else if (getenv("TK_NO_STDERR") != NULL) { + FILE *null = fopen("/dev/null", "w"); + dup2(fileno(null), STDERR_FILENO); } /* diff --git a/macosx/tkMacOSXPrivate.h b/macosx/tkMacOSXPrivate.h index e490d326b..fc5f13cc6 100644 --- a/macosx/tkMacOSXPrivate.h +++ b/macosx/tkMacOSXPrivate.h @@ -132,6 +132,12 @@ STRINGIFY(symbol)); \ } +/* + * This is set to 1 if tests are being run. Defined in tkMacOSXInit.c. + */ + +extern int testsAreRunning; + /* * The structure of a 32-bit XEvent keycode on macOS. It may be viewed as * an unsigned int or as having either two or three bitfields. diff --git a/macosx/tkMacOSXTest.c b/macosx/tkMacOSXTest.c index e7e2a7e03..8bc06550a 100644 --- a/macosx/tkMacOSXTest.c +++ b/macosx/tkMacOSXTest.c @@ -16,7 +16,6 @@ #include "tkMacOSXConstants.h" #include "tkMacOSXWm.h" - /* * Forward declarations of procedures defined later in this file: */ @@ -51,6 +50,12 @@ int TkplatformtestInit( Tcl_Interp *interp) /* Interpreter to add commands to. */ { + /* + * Set a flag indicating that testing is in progress. + */ + + testsAreRunning = 1; + /* * Add commands for platform specific tests on MacOS here. */ diff --git a/tests/filebox.test b/tests/filebox.test index fca339b57..629383184 100644 --- a/tests/filebox.test +++ b/tests/filebox.test @@ -23,6 +23,16 @@ test fileDialog-0.2 {GetFileName: file types: MakeFilter() fails} { regsub -all "\0" $msg {\\0} msg list $x $msg } {1 {bad Macintosh file type "\0\0"}} +test fileDialog-0.3 {GetFileName: file types: bad filetype} \ +-constraints {[tk windowingsystem] eq "aqua"} \ +-body { + # Check for the Aqua crash reported in ticket 080a28104. + + set filename [tk_getOpenFile -filetypes { + {"Invalid extension" {x.y}} + {"All files" {*}} + }] +} -result {} set tk_strictMotif_old $tk_strictMotif