Skip to content

Commit a530ba4

Browse files
author
culler
committed
Backport fix for [080a28104e] and add TK_NO_STDERR processing.
1 parent 94a1c82 commit a530ba4

File tree

6 files changed

+87
-6
lines changed

6 files changed

+87
-6
lines changed

.github/workflows/mac-build.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
ERROR_ON_FAILURES: 1
1414
jobs:
1515
xcode:
16-
runs-on: macos-13
16+
runs-on: macos-15
1717
defaults:
1818
run:
1919
shell: bash
@@ -48,7 +48,7 @@ jobs:
4848
}
4949
- name: Run Tests
5050
run: |
51-
make test | tee out.txt
51+
make TK_NO_STDERR=1 test | tee out.txt
5252
nmatches=$( grep -c "Failed 0" out.txt )
5353
if [ $nmatches -lt 4 ]
5454
then
@@ -57,7 +57,7 @@ jobs:
5757
fi
5858
timeout-minutes: 30
5959
clang:
60-
runs-on: macos-13
60+
runs-on: macos-15
6161
strategy:
6262
matrix:
6363
symbols:
@@ -144,6 +144,7 @@ jobs:
144144
else
145145
function runXvfb {
146146
echo Xvfb not used, this is a --enable-aqua build
147+
export TK_NO_STDERR=1
147148
}
148149
fi
149150
( runXvfb :0; make test-classic; exit $? ) | tee out-classic.txt || {

macosx/tkMacOSXDialog.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ static void setAllowedFileTypes(
3737
NSMutableArray<UTType *> *allowedTypes = [NSMutableArray array];
3838
for (NSString *ext in extensions) {
3939
UTType *uttype = [UTType typeWithFilenameExtension: ext];
40-
[allowedTypes addObject:uttype];
40+
if (uttype) {
41+
[allowedTypes addObject:uttype];
42+
}
4143
}
4244
[panel setAllowedContentTypes:allowedTypes];
4345
} else {
@@ -85,6 +87,41 @@ static filepanelFilterInfo filterInfo;
8587
static NSOpenPanel *openpanel;
8688
static NSSavePanel *savepanel;
8789

90+
/*
91+
* A thread which closes the currently running modal dialog after a timeout.
92+
*/
93+
94+
@interface TKPanelMonitor: NSThread {
95+
@private
96+
NSTimeInterval _timeout;
97+
}
98+
99+
- (id) initWithTimeout: (NSTimeInterval) timeout;
100+
101+
@end
102+
103+
@implementation TKPanelMonitor: NSThread
104+
105+
- (id) initWithTimeout: (NSTimeInterval) timeout {
106+
self = [super init];
107+
if (self) {
108+
_timeout = timeout;
109+
return self;
110+
}
111+
return self;
112+
}
113+
114+
- (void) main
115+
{
116+
[NSThread sleepForTimeInterval:_timeout];
117+
if ([self isCancelled]) {
118+
[NSThread exit];
119+
}
120+
[NSApp stopModalWithCode:modalCancel];
121+
}
122+
@end
123+
124+
88125
static const char *const colorOptionStrings[] = {
89126
"-initialcolor", "-parent", "-title", NULL
90127
};
@@ -866,7 +903,20 @@ Tk_GetOpenFileObjCmd(
866903
parent = nil;
867904
parentIsKey = False;
868905
}
869-
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj, multiple);
906+
TKPanelMonitor *monitor;
907+
if (testsAreRunning) {
908+
/*
909+
* We need the panel to close by itself when running tests.
910+
*/
911+
912+
monitor = [[TKPanelMonitor alloc] initWithTimeout: 1.0];
913+
[monitor start];
914+
}
915+
modalReturnCode = showOpenSavePanel(openpanel, parent, interp, cmdObj,
916+
multiple);
917+
if (testsAreRunning) {
918+
[monitor cancel];
919+
}
870920
if (cmdObj) {
871921
Tcl_DecrRefCount(cmdObj);
872922
}

macosx/tkMacOSXInit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include <sys/stat.h>
2121
#include <sys/utsname.h>
2222

23+
/*
24+
* This flag is set if tests are being run.
25+
*/
26+
27+
int testsAreRunning = 0;
28+
2329
static char tkLibPath[PATH_MAX + 1] = "";
2430

2531
/*
@@ -594,6 +600,9 @@ TkpInit(
594600
#if defined(USE_CUSTOM_EXIT_PROC)
595601
doCleanupFromExit = YES;
596602
#endif
603+
} else if (getenv("TK_NO_STDERR") != NULL) {
604+
FILE *null = fopen("/dev/null", "w");
605+
dup2(fileno(null), STDERR_FILENO);
597606
}
598607

599608
/*

macosx/tkMacOSXPrivate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
STRINGIFY(symbol)); \
133133
}
134134

135+
/*
136+
* This is set to 1 if tests are being run. Defined in tkMacOSXInit.c.
137+
*/
138+
139+
extern int testsAreRunning;
140+
135141
/*
136142
* The structure of a 32-bit XEvent keycode on macOS. It may be viewed as
137143
* an unsigned int or as having either two or three bitfields.

macosx/tkMacOSXTest.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "tkMacOSXConstants.h"
1717
#include "tkMacOSXWm.h"
1818

19-
2019
/*
2120
* Forward declarations of procedures defined later in this file:
2221
*/
@@ -51,6 +50,12 @@ int
5150
TkplatformtestInit(
5251
Tcl_Interp *interp) /* Interpreter to add commands to. */
5352
{
53+
/*
54+
* Set a flag indicating that testing is in progress.
55+
*/
56+
57+
testsAreRunning = 1;
58+
5459
/*
5560
* Add commands for platform specific tests on MacOS here.
5661
*/

tests/filebox.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ test fileDialog-0.2 {GetFileName: file types: MakeFilter() fails} {
2323
regsub -all "\0" $msg {\\0} msg
2424
list $x $msg
2525
} {1 {bad Macintosh file type "\0\0"}}
26+
test fileDialog-0.3 {GetFileName: file types: bad filetype} \
27+
-constraints {[tk windowingsystem] eq "aqua"} \
28+
-body {
29+
# Check for the Aqua crash reported in ticket 080a28104.
30+
31+
set filename [tk_getOpenFile -filetypes {
32+
{"Invalid extension" {x.y}}
33+
{"All files" {*}}
34+
}]
35+
} -result {}
2636

2737
set tk_strictMotif_old $tk_strictMotif
2838

0 commit comments

Comments
 (0)