mirror of
https://github.com/postgres/postgres.git
synced 2025-05-01 01:04:50 +03:00
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 27b62377b4. 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
This commit is contained in:
parent
8b3eb0c584
commit
f8ca22295e
@ -2243,46 +2243,44 @@ check_icu_locale_encoding(int user_enc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check that ICU accepts the locale name; or if not specified, retrieve the
|
* Determine default ICU locale by opening the default collator and reading
|
||||||
* default ICU locale.
|
* its locale.
|
||||||
|
*
|
||||||
|
* NB: The default collator (opened using NULL) is different from the collator
|
||||||
|
* for the root locale (opened with "", "und", or "root"). The former depends
|
||||||
|
* on the environment (useful at initdb time) and the latter does not.
|
||||||
*/
|
*/
|
||||||
static void
|
static char *
|
||||||
check_icu_locale(void)
|
default_icu_locale(void)
|
||||||
{
|
{
|
||||||
#ifdef USE_ICU
|
#ifdef USE_ICU
|
||||||
UCollator *collator;
|
UCollator *collator;
|
||||||
UErrorCode status;
|
UErrorCode status;
|
||||||
|
const char *valid_locale;
|
||||||
|
char *default_locale;
|
||||||
|
|
||||||
status = U_ZERO_ERROR;
|
status = U_ZERO_ERROR;
|
||||||
collator = ucol_open(icu_locale, &status);
|
collator = ucol_open(NULL, &status);
|
||||||
|
if (U_FAILURE(status))
|
||||||
|
pg_fatal("could not open collator for default locale: %s",
|
||||||
|
u_errorName(status));
|
||||||
|
|
||||||
|
status = U_ZERO_ERROR;
|
||||||
|
valid_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
|
||||||
|
&status);
|
||||||
if (U_FAILURE(status))
|
if (U_FAILURE(status))
|
||||||
{
|
{
|
||||||
if (icu_locale)
|
ucol_close(collator);
|
||||||
pg_fatal("could not open collator for locale \"%s\": %s",
|
pg_fatal("could not determine default ICU locale");
|
||||||
icu_locale, u_errorName(status));
|
|
||||||
else
|
|
||||||
pg_fatal("could not open collator for default locale: %s",
|
|
||||||
u_errorName(status));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if not specified, get locale from default collator */
|
default_locale = pg_strdup(valid_locale);
|
||||||
if (icu_locale == NULL)
|
|
||||||
{
|
|
||||||
const char *default_locale;
|
|
||||||
|
|
||||||
status = U_ZERO_ERROR;
|
|
||||||
default_locale = ucol_getLocaleByType(collator, ULOC_VALID_LOCALE,
|
|
||||||
&status);
|
|
||||||
if (U_FAILURE(status))
|
|
||||||
{
|
|
||||||
ucol_close(collator);
|
|
||||||
pg_fatal("could not determine default ICU locale");
|
|
||||||
}
|
|
||||||
|
|
||||||
icu_locale = pg_strdup(default_locale);
|
|
||||||
}
|
|
||||||
|
|
||||||
ucol_close(collator);
|
ucol_close(collator);
|
||||||
|
|
||||||
|
return default_locale;
|
||||||
|
#else
|
||||||
|
pg_fatal("ICU is not supported in this build");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2339,7 +2337,9 @@ setlocales(void)
|
|||||||
|
|
||||||
if (locale_provider == COLLPROVIDER_ICU)
|
if (locale_provider == COLLPROVIDER_ICU)
|
||||||
{
|
{
|
||||||
check_icu_locale();
|
/* acquire default locale from the environment, if not specified */
|
||||||
|
if (icu_locale == NULL)
|
||||||
|
icu_locale = default_icu_locale();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* In supported builds, the ICU locale ID will be checked by the
|
* In supported builds, the ICU locale ID will be checked by the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user