Skip to content

Commit

Permalink
Backport fix for [080a28104e] and add TK_NO_STDERR processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
culler committed Jan 27, 2025
1 parent 94a1c82 commit a530ba4
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 6 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
ERROR_ON_FAILURES: 1
jobs:
xcode:
runs-on: macos-13
runs-on: macos-15
defaults:
run:
shell: bash
Expand Down Expand Up @@ -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
Expand All @@ -57,7 +57,7 @@ jobs:
fi
timeout-minutes: 30
clang:
runs-on: macos-13
runs-on: macos-15
strategy:
matrix:
symbols:
Expand Down Expand Up @@ -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 || {
Expand Down
54 changes: 52 additions & 2 deletions macosx/tkMacOSXDialog.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ static void setAllowedFileTypes(
NSMutableArray<UTType *> *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 {
Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -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);
}
Expand Down
9 changes: 9 additions & 0 deletions macosx/tkMacOSXInit.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include <sys/stat.h>
#include <sys/utsname.h>

/*
* This flag is set if tests are being run.
*/

int testsAreRunning = 0;

static char tkLibPath[PATH_MAX + 1] = "";

/*
Expand Down Expand Up @@ -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);
}

/*
Expand Down
6 changes: 6 additions & 0 deletions macosx/tkMacOSXPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion macosx/tkMacOSXTest.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include "tkMacOSXConstants.h"
#include "tkMacOSXWm.h"


/*
* Forward declarations of procedures defined later in this file:
*/
Expand Down Expand Up @@ -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.
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/filebox.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit a530ba4

Please sign in to comment.