Skip to content

Commit fab9824

Browse files
miss-islingtonchrstphrchvzned-deily
authored
[3.12] gh-110950: add upstream Tk fixes to macOS installer. (GH-111041) (#112294)
Add upstream Tk patches for three problems affecting tkinter users: - Update macOS installer to include a fix accepted by upstream Tcl/Tk for a crash encountered after the first :meth:`tkinter.Tk` instance is destroyed. (gh-92603) - Update macOS installer to include an upstream Tcl/Tk fix for the ``ttk::ThemeChanged`` error encountered in Tkinter. (gh-71383) - Update macOS installer to include an upstream Tcl/Tk fix for the ``Secure coding is not enabled for restorable state!`` warning encountered in Tkinter on macOS 14 Sonoma. (gh-110950) (cherry picked from commit d67f947) Co-authored-by: Christopher Chavez <chrischavez@gmx.us> Co-authored-by: Ned Deily <nad@python.org>
1 parent 7e70e2e commit fab9824

7 files changed

+206
-2
lines changed

Diff for: Mac/BuildScript/backport_gh110950_fix.patch

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From https://core.tcl-lang.org/tk/info/ed7cfbac8db11aa0
2+
3+
Note: the diff here is hand-tweaked so that it applies cleanly to both Tk 8.6.8 and 8.6.13.
4+
5+
diff --git a/macosx/tkMacOSXInit.c b/macosx/tkMacOSXInit.c
6+
index 71d7c3385..e6a68356c 100644
7+
--- a/macosx/tkMacOSXInit.c
8+
+++ b/macosx/tkMacOSXInit.c
9+
@@ -128,6 +128,16 @@ static int TkMacOSXGetAppPathCmd(ClientData cd, Tcl_Interp *ip,
10+
observe(NSApplicationDidChangeScreenParametersNotification, displayChanged:);
11+
observe(NSTextInputContextKeyboardSelectionDidChangeNotification, keyboardChanged:);
12+
#undef observe
13+
+}
14+
+
15+
+
16+
+/*
17+
+ * Fix for 10b38a7a7c.
18+
+ */
19+
+
20+
+- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
21+
+{
22+
+ return YES;
23+
}
24+
25+
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification

Diff for: Mac/BuildScript/backport_gh71383_fix.patch

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
Adapted from https://core.tcl-lang.org/tk/info/b1876b9ebc4b
2+
3+
Index: generic/tkInt.h
4+
==================================================================
5+
--- a/generic/tkInt.h.orig
6+
+++ b/generic/tkInt.h
7+
@@ -1094,10 +1094,11 @@
8+
/*
9+
* Themed widget set init function:
10+
*/
11+
12+
MODULE_SCOPE int Ttk_Init(Tcl_Interp *interp);
13+
+MODULE_SCOPE void Ttk_TkDestroyedHandler(Tcl_Interp *interp);
14+
15+
/*
16+
* Internal functions shared among Tk modules but not exported to the outside
17+
* world:
18+
*/
19+
20+
Index: generic/tkWindow.c
21+
==================================================================
22+
--- a/generic/tkWindow.c.orig
23+
+++ b/generic/tkWindow.c
24+
@@ -1619,10 +1619,11 @@
25+
TkBindFree(winPtr->mainPtr);
26+
TkDeleteAllImages(winPtr->mainPtr);
27+
TkFontPkgFree(winPtr->mainPtr);
28+
TkFocusFree(winPtr->mainPtr);
29+
TkStylePkgFree(winPtr->mainPtr);
30+
+ Ttk_TkDestroyedHandler(winPtr->mainPtr->interp);
31+
32+
/*
33+
* When embedding Tk into other applications, make sure that all
34+
* destroy events reach the server. Otherwise the embedding
35+
* application may also attempt to destroy the windows, resulting
36+
37+
Index: generic/ttk/ttkTheme.c
38+
==================================================================
39+
--- a/generic/ttk/ttkTheme.c.orig
40+
+++ b/generic/ttk/ttkTheme.c
41+
@@ -415,17 +415,10 @@
42+
StylePackageData *pkgPtr = (StylePackageData *)clientData;
43+
Tcl_HashSearch search;
44+
Tcl_HashEntry *entryPtr;
45+
Cleanup *cleanup;
46+
47+
- /*
48+
- * Cancel any pending ThemeChanged calls:
49+
- */
50+
- if (pkgPtr->themeChangePending) {
51+
- Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
52+
- }
53+
-
54+
/*
55+
* Free themes.
56+
*/
57+
entryPtr = Tcl_FirstHashEntry(&pkgPtr->themeTable, &search);
58+
while (entryPtr != NULL) {
59+
@@ -528,10 +521,29 @@
60+
if (!pkgPtr->themeChangePending) {
61+
Tcl_DoWhenIdle(ThemeChangedProc, pkgPtr);
62+
pkgPtr->themeChangePending = 1;
63+
}
64+
}
65+
+
66+
+/* Ttk_TkDestroyedHandler --
67+
+ * See bug [310c74ecf440]: idle calls to ThemeChangedProc()
68+
+ * need to be canceled when Tk is destroyed, since the interp
69+
+ * may still be active afterward; canceling them from
70+
+ * Ttk_StylePkgFree() would be too late.
71+
+ */
72+
+void Ttk_TkDestroyedHandler(
73+
+ Tcl_Interp* interp)
74+
+{
75+
+ StylePackageData* pkgPtr = GetStylePackageData(interp);
76+
+
77+
+ /*
78+
+ * Cancel any pending ThemeChanged calls:
79+
+ */
80+
+ if (pkgPtr->themeChangePending) {
81+
+ Tcl_CancelIdleCall(ThemeChangedProc, pkgPtr);
82+
+ }
83+
+}
84+
85+
/*
86+
* Ttk_CreateTheme --
87+
* Create a new theme and register it in the global theme table.
88+
*
89+

Diff for: Mac/BuildScript/backport_gh92603_fix.patch

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
Accepted upstream for release in Tk 8.6.14:
2+
https://core.tcl-lang.org/tk/info/cf3830280b
3+
4+
--- tk8.6.13/macosx/tkMacOSXWindowEvent.c.orig
5+
+++ tk8.6.13-patched/macosx/tkMacOSXWindowEvent.c
6+
@@ -239,8 +239,8 @@ extern NSString *NSWindowDidOrderOffScreenNotification;
7+
if (winPtr) {
8+
TKContentView *view = [window contentView];
9+
10+
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
11+
- if (@available(macOS 10.15, *)) {
12+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
13+
+ if (@available(macOS 10.14, *)) {
14+
[view viewDidChangeEffectiveAppearance];
15+
}
16+
#endif
17+
@@ -1237,29 +1237,8 @@ static const char *const accentNames[] = {
18+
} else if (effectiveAppearanceName == NSAppearanceNameDarkAqua) {
19+
TkSendVirtualEvent(tkwin, "DarkAqua", NULL);
20+
}
21+
- if ([NSApp macOSVersion] < 101500) {
22+
-
23+
- /*
24+
- * Mojave cannot handle the KVO shenanigans that we need for the
25+
- * highlight and accent color notifications.
26+
- */
27+
-
28+
- return;
29+
- }
30+
if (!defaultColor) {
31+
defaultColor = [NSApp macOSVersion] < 110000 ? "Blue" : "Multicolor";
32+
- preferences = [[NSUserDefaults standardUserDefaults] retain];
33+
-
34+
- /*
35+
- * AppKit calls this method when the user changes the Accent Color
36+
- * but not when the user changes the Highlight Color. So we register
37+
- * to receive KVO notifications for Highlight Color as well.
38+
- */
39+
-
40+
- [preferences addObserver:self
41+
- forKeyPath:@"AppleHighlightColor"
42+
- options:NSKeyValueObservingOptionNew
43+
- context:NULL];
44+
}
45+
NSString *accent = [preferences stringForKey:@"AppleAccentColor"];
46+
NSArray *words = [[preferences stringForKey:@"AppleHighlightColor"]
47+
--- tk8.6.13/macosx/tkMacOSXWm.c.orig
48+
+++ tk8.6.13-patched/macosx/tkMacOSXWm.c
49+
@@ -1289,6 +1289,11 @@ TkWmDeadWindow(
50+
[NSApp _setMainWindow:nil];
51+
}
52+
[deadNSWindow close];
53+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
54+
+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
55+
+ [preferences removeObserver:deadNSWindow.contentView
56+
+ forKeyPath:@"AppleHighlightColor"];
57+
+#endif
58+
[deadNSWindow release];
59+
60+
#if DEBUG_ZOMBIES > 1
61+
@@ -6763,6 +6768,21 @@ TkMacOSXMakeRealWindowExist(
62+
}
63+
TKContentView *contentView = [[TKContentView alloc]
64+
initWithFrame:NSZeroRect];
65+
+#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101400
66+
+ NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
67+
+
68+
+ /*
69+
+ * AppKit calls the viewDidChangeEffectiveAppearance method when the
70+
+ * user changes the Accent Color but not when the user changes the
71+
+ * Highlight Color. So we register to receive KVO notifications for
72+
+ * Highlight Color as well.
73+
+ */
74+
+
75+
+ [preferences addObserver:contentView
76+
+ forKeyPath:@"AppleHighlightColor"
77+
+ options:NSKeyValueObservingOptionNew
78+
+ context:NULL];
79+
+#endif
80+
[window setContentView:contentView];
81+
[contentView release];
82+
[window setDelegate:NSApp];

Diff for: Mac/BuildScript/build-installer.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,14 +261,14 @@ def library_recipes():
261261
tcl_checksum='81656d3367af032e0ae6157eff134f89'
262262

263263
tk_checksum='5e0faecba458ee1386078fb228d008ba'
264-
tk_patches = ['tk868_on_10_8_10_9.patch']
264+
tk_patches = ['backport_gh71383_fix.patch', 'tk868_on_10_8_10_9.patch', 'backport_gh110950_fix.patch']
265265

266266
else:
267267
tcl_tk_ver='8.6.13'
268268
tcl_checksum='43a1fae7412f61ff11de2cfd05d28cfc3a73762f354a417c62370a54e2caf066'
269269

270270
tk_checksum='2e65fa069a23365440a3c56c556b8673b5e32a283800d8d9b257e3f584ce0675'
271-
tk_patches = [ ]
271+
tk_patches = ['backport_gh92603_fix.patch', 'backport_gh71383_fix.patch', 'backport_gh110950_fix.patch']
272272

273273

274274
base_url = "https://prdownloads.sourceforge.net/tcl/{what}{version}-src.tar.gz"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Update macOS installer to include a fix accepted by upstream Tcl/Tk
2+
for a crash encountered after the first :meth:`tkinter.Tk` instance
3+
is destroyed.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update macOS installer to include an upstream Tcl/Tk fix
2+
for the ``ttk::ThemeChanged`` error encountered in Tkinter.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Update macOS installer to include an upstream Tcl/Tk fix for the
2+
``Secure coding is not enabled for restorable state!`` warning
3+
encountered in Tkinter on macOS 14 Sonoma.

0 commit comments

Comments
 (0)