Merge branch 'fix-win32-g-module-symbol-flaky' into 'master'

Fix g_module_symbol() under Windows sometimes not succeeding

Closes gtk#3213

See merge request GNOME/glib!1665
This commit is contained in:
Philip Withnall 2020-09-30 14:30:15 +00:00
commit 2d788652fd

View File

@ -131,7 +131,20 @@ find_in_any_module_using_toolhelp (const gchar *symbol_name)
/* Under UWP, Module32Next and Module32First are not available since we're
* not allowed to search in the address space of arbitrary loaded DLLs */
#if !defined(G_WINAPI_ONLY_APP)
if ((snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0)) == (HANDLE) -1)
/* https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot#remarks
* If the function fails with ERROR_BAD_LENGTH, retry the function until it succeeds. */
while (TRUE)
{
snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0);
if (snapshot == INVALID_HANDLE_VALUE && GetLastError () == ERROR_BAD_LENGTH)
{
g_thread_yield ();
continue;
}
break;
}
if (snapshot == INVALID_HANDLE_VALUE)
return NULL;
me32.dwSize = sizeof (me32);