gh-150836: Mount embedded Tk ZIP in _tkinter on Windows#151562
Open
jjhelmus wants to merge 1 commit into
Open
Conversation
Tcl/Tk 9 may embed the Tk script library in the Tk DLL on Windows. This embedded library is not found by Tcl by default. Mount the loaded Tk DLL as a zipfs archive before calling Tk_Init(), so Tk can find its embedded tk_library using its existing library discovery logic. Preserve Tk_Init()'s normal path if the library is not embedded.
zooba
reviewed
Jun 17, 2026
| wchar_t tk_path[MAX_PATH]; | ||
| DWORD path_len = GetModuleFileNameW(tk_module, tk_path, MAX_PATH); | ||
|
|
||
| if (path_len == 0 || path_len >= MAX_PATH) { |
Member
There was a problem hiding this comment.
We can't assume MAX_PATH, unfortunately, since it's quite likely that Python could be running in a long path. At a minimum, use 512 instead (which is what is used in dynload_win.c for importing native modules), or we have to do a loop that increases (doubles) the buffer size until path_len < buffer_len.
Member
There was a problem hiding this comment.
If it can be done with Tcl's APIs, go for it.
| Tcl_DStringInit(&utf8_path); | ||
| Tcl_WCharToUtfDString(tk_path, path_len, &utf8_path); | ||
| (void) TclZipfs_Mount(NULL, Tcl_DStringValue(&utf8_path), | ||
| "//zipfs:/lib/tk", NULL); |
Member
There was a problem hiding this comment.
I assume this handles re-mounting without an issue? It seems like it could be called multiple times by someone's code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tcl/Tk 9 may embed the Tk script library in the Tk DLL on Windows. This embedded library is not found by Tcl by default.
Mount the loaded Tk DLL as a zipfs archive before calling Tk_Init(), so Tk can find its embedded tk_library using its existing library discovery logic.
Preserve Tk_Init()'s normal path if the library is not embedded.