Merge branch 'backport-1665-win32-module-glib-2-64' into 'glib-2-64'

Backport !1665 “Fix g_module_symbol() under Windows sometimes not succeeding” to glib-2-64

See merge request GNOME/glib!1666
This commit is contained in:
Sebastian Dröge 2020-10-01 06:02:37 +00:00
commit 6711f7d2f4

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 /* Under UWP, Module32Next and Module32First are not available since we're
* not allowed to search in the address space of arbitrary loaded DLLs */ * not allowed to search in the address space of arbitrary loaded DLLs */
#if !defined(G_WINAPI_ONLY_APP) #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; return NULL;
me32.dwSize = sizeof (me32); me32.dwSize = sizeof (me32);