From 9d325ae2e4939257233fdbcba53104f7802b6764 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Thu, 10 Feb 2022 17:29:25 +0100 Subject: [PATCH] Fix loading tk on windows when current process has >1024 modules. --- src/_tkagg.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index 7f72ed2ea6af..5a5616bea539 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -256,25 +256,32 @@ int load_tcl(T lib) void load_tkinter_funcs(void) { - // Load Tcl/Tk functions by searching all modules in current process. - HMODULE hMods[1024]; - HANDLE hProcess; - DWORD cbNeeded; - unsigned int i; + HANDLE process = GetCurrentProcess(); // Pseudo-handle, doesn't need closing. + HMODULE* modules = NULL; + DWORD size; + if (!EnumProcessModules(process, NULL, 0, &size)) { + PyErr_SetFromWindowsErr(0); + goto exit; + } + if (!(modules = static_cast(malloc(size)))) { + PyErr_NoMemory(); + goto exit; + } + if (!EnumProcessModules(process, modules, size, &size)) { + PyErr_SetFromWindowsErr(0); + goto exit; + } bool tcl_ok = false, tk_ok = false; - // Returns pseudo-handle that does not need to be closed - hProcess = GetCurrentProcess(); - // Iterate through modules in this process looking for Tcl/Tk names. - if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { - for (i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { - if (!tcl_ok) { - tcl_ok = load_tcl(hMods[i]); - } - if (!tk_ok) { - tk_ok = load_tk(hMods[i]); - } + for (unsigned i = 0; i < size / sizeof(HMODULE); ++i) { + if (!tcl_ok) { + tcl_ok = load_tcl(modules[i]); + } + if (!tk_ok) { + tk_ok = load_tk(modules[i]); } } +exit: + free(modules); } #else // not Windows pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy