src/fcxml.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) New commits: commit 16bbb5340bab0923c1c9bbf4305d5cec3c198799 Author: Francesco Pretto <ceztko@xxxxxxxxx> Date: Tue Oct 26 19:31:23 2021 +0200 WIN32: Fix pGetSystemWindowsDirectory found initialized during FcConfigParseAndLoadFromMemory Trying to early loading a custom fonts.xml created on the fly results in the pGetSystemWindowsDirectory function pointer being found intialized. Normally the initialization is performed in the default configuration loading. The commit factorizes the lazy initialization of both WIN32 getters (together with pSHGetFolderPathA) in a function and call it when actually needed. diff --git a/src/fcxml.c b/src/fcxml.c index 6b0f613..82a46f2 100644 --- a/src/fcxml.c +++ b/src/fcxml.c @@ -59,6 +59,10 @@ #ifdef _WIN32 #include <mbstring.h> extern FcChar8 fontconfig_instprefix[]; +pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory = NULL; +pfnSHGetFolderPathA pSHGetFolderPathA = NULL; +static void +_ensureWin32GettersReady(); #endif static FcChar8 *__fc_userdir = NULL; @@ -1384,6 +1388,7 @@ _get_real_paths_from_prefix(FcConfigParse *parse, const FcChar8 *path, const FcC { int rc; path = buffer; + _ensureWin32GettersReady(); rc = pGetSystemWindowsDirectory ((LPSTR) buffer, sizeof (buffer) - 20); if (rc == 0 || rc > sizeof (buffer) - 20) { @@ -3451,11 +3456,6 @@ bail0: return ret || !complain; } -#ifdef _WIN32 -pfnGetSystemWindowsDirectory pGetSystemWindowsDirectory = NULL; -pfnSHGetFolderPathA pSHGetFolderPathA = NULL; -#endif - static FcBool FcConfigParseAndLoadFromMemoryInternal (FcConfig *config, const FcChar8 *filename, @@ -3601,19 +3601,7 @@ _FcConfigParse (FcConfig *config, FcStrBufInit (&reason, NULL, 0); #ifdef _WIN32 - if (!pGetSystemWindowsDirectory) - { - HMODULE hk32 = GetModuleHandleA("kernel32.dll"); - if (!(pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory) GetProcAddress(hk32, "GetSystemWindowsDirectoryA"))) - pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory) GetWindowsDirectory; - } - if (!pSHGetFolderPathA) - { - HMODULE hSh = LoadLibraryA("shfolder.dll"); - /* the check is done later, because there is no provided fallback */ - if (hSh) - pSHGetFolderPathA = (pfnSHGetFolderPathA) GetProcAddress(hSh, "SHGetFolderPathA"); - } + _ensureWin32GettersReady(); #endif filename = FcConfigGetFilename (config, name); @@ -3736,6 +3724,26 @@ FcConfigParseAndLoadFromMemory (FcConfig *config, return FcConfigParseAndLoadFromMemoryInternal (config, (const FcChar8 *)"memory", buffer, complain, FcTrue); } +#ifdef _WIN32 +static void +_ensureWin32GettersReady() +{ + if (!pGetSystemWindowsDirectory) + { + HMODULE hk32 = GetModuleHandleA("kernel32.dll"); + if (!(pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory)GetProcAddress(hk32, "GetSystemWindowsDirectoryA"))) + pGetSystemWindowsDirectory = (pfnGetSystemWindowsDirectory)GetWindowsDirectory; + } + if (!pSHGetFolderPathA) + { + HMODULE hSh = LoadLibraryA("shfolder.dll"); + /* the check is done later, because there is no provided fallback */ + if (hSh) + pSHGetFolderPathA = (pfnSHGetFolderPathA)GetProcAddress(hSh, "SHGetFolderPathA"); + } +} +#endif // _WIN32 + #define __fcxml__ #include "fcaliastail.h" #undef __fcxml__