Skip to content

Commit baaa534

Browse files
committed
Support long paths when mounting the embedded Tk ZIP
1 parent 6b57a35 commit baaa534

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

Modules/_tkinter.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,25 @@ static void
184184
mount_tk_dll_zip(void)
185185
{
186186
HINSTANCE tk_module = Tk_GetHINSTANCE();
187-
wchar_t tk_path[MAX_PATH];
188-
DWORD path_len = GetModuleFileNameW(tk_module, tk_path, MAX_PATH);
187+
wchar_t *tk_path = NULL;
188+
DWORD path_len = 0;
189+
for (DWORD buffer_len = 256;
190+
tk_path == NULL && buffer_len < (1024 * 1024);
191+
buffer_len *= 2)
192+
{
193+
tk_path = (wchar_t *)PyMem_RawMalloc(
194+
buffer_len * sizeof(*tk_path));
195+
if (tk_path != NULL) {
196+
path_len = GetModuleFileNameW(tk_module, tk_path, buffer_len);
197+
if (path_len == buffer_len) {
198+
PyMem_RawFree(tk_path);
199+
tk_path = NULL;
200+
}
201+
}
202+
}
189203

190-
if (path_len == 0 || path_len >= MAX_PATH) {
204+
if (tk_path == NULL || path_len == 0) {
205+
PyMem_RawFree(tk_path);
191206
return;
192207
}
193208

@@ -198,6 +213,7 @@ mount_tk_dll_zip(void)
198213
(void) TclZipfs_Mount(NULL, Tcl_DStringValue(&utf8_path),
199214
"//zipfs:/lib/tk", NULL);
200215
Tcl_DStringFree(&utf8_path);
216+
PyMem_RawFree(tk_path);
201217
}
202218
#endif
203219

0 commit comments

Comments
 (0)