Skip to content

Commit f8ca222

Browse files
committed
initdb: replace check_icu_locale() with default_icu_locale().
The extra checks done in check_icu_locale() are not necessary. An existing comment already pointed out that the checks would be done during post-bootstrap initialization, when the locale is opened by the backend. This was a mistake in commit 27b6237. This commit creates a simpler function default_icu_locale() to just return the locale of the default collator. Discussion: https://postgr.es/m/04182066-7655-344a-b8b7-040b1b2490fb%40enterprisedb.com Reviewed-by: Peter Eisentraut
1 parent 8b3eb0c commit f8ca222

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/bin/initdb/initdb.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,46 +2243,44 @@ check_icu_locale_encoding(int user_enc)
22432243
}
22442244

22452245
/*
2246-
* Check that ICU accepts the locale name; or if not specified, retrieve the
2247-
* default ICU locale.
2246+
* Determine default ICU locale by opening the default collator and reading
2247+
* its locale.
2248+
*
2249+
* NB: The default collator (opened using NULL) is different from the collator
2250+
* for the root locale (opened with "", "und", or "root"). The former depends
2251+
* on the environment (useful at initdb time) and the latter does not.
22482252
*/
2249-
static void
2250-
check_icu_locale(void)
2253+
static char *
2254+
default_icu_locale(void)
22512255
{
22522256
#ifdef USE_ICU
22532257
UCollator *collator;
22542258
UErrorCode status;
2259+
const char *valid_locale;
2260+
char *default_locale;
22552261

22562262
status = U_ZERO_ERROR;
2257-
collator = ucol_open(icu_locale, &status);
2263+
collator = ucol_open(NULL, &status);
22582264
if (U_FAILURE(status))
2259-
{
2260-
if (icu_locale)
2261-
pg_fatal("could not open collator for locale \"%s\": %s",
2262-
icu_locale, u_errorName(status));
2263-
else
2264-
pg_fatal("could not open collator for default locale: %s",
2265-
u_errorName(status));
2266-
}
2265+
pg_fatal("could not open collator for default locale: %s",
2266+
u_errorName(status));
22672267

2268-
/* if not specified, get locale from default collator */
2269-
if (icu_locale == NULL)
2268+
status = U_ZERO_ERROR;
2269+
valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
2270+
&status);
2271+
if (U_FAILURE(status))
22702272
{
2271-
const char *default_locale;
2272-
2273-
status = U_ZERO_ERROR;
2274-
default_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
2275-
&status);
2276-
if (U_FAILURE(status))
2277-
{
2278-
ucol_close(collator);
2279-
pg_fatal("could not determine default ICU locale");
2280-
}
2281-
2282-
icu_locale = pg_strdup(default_locale);
2273+
ucol_close(collator);
2274+
pg_fatal("could not determine default ICU locale");
22832275
}
22842276

2277+
default_locale = pg_strdup(valid_locale);
2278+
22852279
ucol_close(collator);
2280+
2281+
return default_locale;
2282+
#else
2283+
pg_fatal("ICU is not supported in this build");
22862284
#endif
22872285
}
22882286

@@ -2339,7 +2337,9 @@ setlocales(void)
23392337

23402338
if (locale_provider == COLLPROVIDER_ICU)
23412339
{
2342-
check_icu_locale();
2340+
/* acquire default locale from the environment, if not specified */
2341+
if (icu_locale == NULL)
2342+
icu_locale = default_icu_locale();
23432343

23442344
/*
23452345
* In supported builds, the ICU locale ID will be checked by the

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy