Here's another mystery from Windows + MinGW. Although "fairywren" is green, that is because it lacks ICU, which would activate extra tests. CI is green too, but the optional CI task "Windows - Server 2019, MinGW64 - Meson" has ICU and it is now failing if you trigger it[1] after commit 35eeea62, in initdb/001_initdb:
[05:43:49.764] | 146/305 - options --locale-provider=icu --locale=und --lc-*=C: no stderr FAIL ... because it logs a warning to stderr: WARNING: no usable system locales were found I can only assume there was some extra dependency on setlocale() global state changes in the removed code. I don't quite get it, but whatever the reason, it's less than helpful to have different compilers taking different code paths on our weirdest OS that most of us don't use, so I propose to push this change to take the regular MSVC code path for MinGW too, when looking up code pages. Somehow, this fixes that, though it'd probably take someone with a local MinGW setup to dig into what exactly is happening there. (There are plenty more places where we do something different for MinGW. I suspect they are all obsolete problems. We should probably just harmonise everything and see what breaks now that we have a CI system, but that can be for another day.) That warning is from pg_import_system_locales(), which is new-ish (v16) on that OS. It was recently discovered to trigger a pre-existing problem[2]: the simple setlocale() save/restore pattern doesn't work in general on Windows, because some local names are non-ASCII, and the restore can fail (abort in the system library due to bad encoding, because the intermediate setlocale() changed the expected encoding of the locale name itself). So it's good that we aren't doing that anymore in this location; I'm just thinking out loud about whether that phenomenon could also be somehow connected to this failure, though I don't see it. Another realisation is that my pg_localeconv_r() patch, which can't avoid a thread-safe setlocale() save-and-restore on that OS (and might finish up being the only one left in the tree by the time we're done?), had better use wsetlocale() instead to defend itself against that particular madness. [1] https://cirrus-ci.com/task/5928104793735168 [2] https://www.postgresql.org/message-id/CA%2BhUKG%2BFxeRLURZ%3Dn8NPyLwgjFds_SqU_cQvE40ks6RQKUGbGg%40mail.gmail.com
From 21acdecdeec65bc1f847c58d5afffd390e826c73 Mon Sep 17 00:00:00 2001 From: Thomas Munro <thomas.mu...@gmail.com> Date: Wed, 14 Aug 2024 09:19:13 +1200 Subject: [PATCH] Harmonize MinGW CODESET lookup with MSVC. Historically, MinGW environments lacked some Win32 calls, so we took a different code path in win32_langinfo(). Somehow, the code change in commit 35eeea62 (removing setlocale() calls) caused one particular 001_initdb.pl test to fail on MinGW + ICU builds, because pg_import_system_collations() found no collations. It might take a MinGW user to discover the exact reason. Updating that function to use the same code as MSVC seems to fix that test, so lets do that. (There are plenty more places that test for MSVC unnecessarily, to be investigated later.) While here, also rename the helper function win32_langinfo() to win32_get_codeset(), to explain what it does less confusingly. --- src/port/chklocale.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/port/chklocale.c b/src/port/chklocale.c index 99e27ed6de..9506cd87ed 100644 --- a/src/port/chklocale.c +++ b/src/port/chklocale.c @@ -193,7 +193,7 @@ static const struct encoding_match encoding_match_list[] = { #ifdef WIN32 /* - * On Windows, use CP<code page number> instead of the nl_langinfo() result + * On Windows, use CP<code page number> instead of CODESET. * * This routine uses GetLocaleInfoEx() to parse short locale names like * "de-DE", "fr-FR", etc. If those cannot be parsed correctly process falls @@ -203,12 +203,10 @@ static const struct encoding_match encoding_match_list[] = { * Returns a malloc()'d string for the caller to free. */ static char * -win32_langinfo(const char *ctype) +win32_get_codeset(const char *ctype) { char *r = NULL; char *codepage; - -#if defined(_MSC_VER) uint32 cp; WCHAR wctype[LOCALE_NAME_MAX_LENGTH]; @@ -233,7 +231,6 @@ win32_langinfo(const char *ctype) } } else -#endif { /* * Locale format on Win32 is <Language>_<Country>.<CodePage>. For @@ -336,7 +333,7 @@ pg_get_encoding_from_locale(const char *ctype, bool write_message) freelocale(loc); #else - sys = win32_langinfo(ctype); + sys = win32_get_codeset(ctype); #endif if (!sys) -- 2.39.2