Harmonize MinGW CODESET lookup with MSVC.
authorThomas Munro <tmunro@postgresql.org>
Wed, 14 Aug 2024 03:02:12 +0000 (15:02 +1200)
committerThomas Munro <tmunro@postgresql.org>
Wed, 14 Aug 2024 03:04:14 +0000 (15:04 +1200)
Historically, MinGW environments lacked some Windows API 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; it's not
really a general langinfo() substitute.

Noticed by triggering the optional MinGW CI task; no build farm animals
failed.

Discussion: https://postgr.es/m/CA%2BhUKGKBWfhXQ3J%2B2Lj5PhKvQnGD%3DsywA0XQcb7boTCf%3DerVLg%40mail.gmail.com

src/port/chklocale.c

index 99e27ed6de552111b93a3268e21ecf791bb27c75..9506cd87ed868f431237da6d42f6df324a1e1db7 100644 (file)
@@ -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)