Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8f1758b

Browse filesBrowse files
authored
Merge pull request #22445 from anntzer/wtk
Fix loading tk on windows when current process has >1024 modules.
2 parents 2bb9b03 + 9d325ae commit 8f1758b
Copy full SHA for 8f1758b

File tree

Expand file treeCollapse file tree

1 file changed

+23
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+23
-16
lines changed

‎src/_tkagg.cpp

Copy file name to clipboardExpand all lines: src/_tkagg.cpp
+23-16Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,32 @@ int load_tcl(T lib)
256256

257257
void load_tkinter_funcs(void)
258258
{
259-
// Load Tcl/Tk functions by searching all modules in current process.
260-
HMODULE hMods[1024];
261-
HANDLE hProcess;
262-
DWORD cbNeeded;
263-
unsigned int i;
259+
HANDLE process = GetCurrentProcess(); // Pseudo-handle, doesn't need closing.
260+
HMODULE* modules = NULL;
261+
DWORD size;
262+
if (!EnumProcessModules(process, NULL, 0, &size)) {
263+
PyErr_SetFromWindowsErr(0);
264+
goto exit;
265+
}
266+
if (!(modules = static_cast<HMODULE*>(malloc(size)))) {
267+
PyErr_NoMemory();
268+
goto exit;
269+
}
270+
if (!EnumProcessModules(process, modules, size, &size)) {
271+
PyErr_SetFromWindowsErr(0);
272+
goto exit;
273+
}
264274
bool tcl_ok = false, tk_ok = false;
265-
// Returns pseudo-handle that does not need to be closed
266-
hProcess = GetCurrentProcess();
267-
// Iterate through modules in this process looking for Tcl/Tk names.
268-
if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
269-
for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) {
270-
if (!tcl_ok) {
271-
tcl_ok = load_tcl(hMods[i]);
272-
}
273-
if (!tk_ok) {
274-
tk_ok = load_tk(hMods[i]);
275-
}
275+
for (unsigned i = 0; i < size / sizeof(HMODULE); ++i) {
276+
if (!tcl_ok) {
277+
tcl_ok = load_tcl(modules[i]);
278+
}
279+
if (!tk_ok) {
280+
tk_ok = load_tk(modules[i]);
276281
}
277282
}
283+
exit:
284+
free(modules);
278285
}
279286

280287
#else // not Windows

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.