mirror of
https://github.com/postgres/postgres.git
synced 2025-07-31 22:04:40 +03:00
Fix global ICU collations for ICU < 54
createdb() didn't check for collation attributes validity, which has to be done explicitly on ICU < 54. It also forgot to close the ICU collator opened during the check which leaks some memory. To fix both, add a new check_icu_locale() that does all the appropriate verification and close the ICU collator. initdb also had some partial check for ICU < 54. To have consistent error reporting across major ICU versions, and get rid of the need to include ucol.h, remove the partial check there. The backend will report an error if needed during the post-boostrap iniitialization phase. Author: Julien Rouhaud <julien.rouhaud@free.fr> Discussion: https://www.postgresql.org/message-id/20220319041459.qqqiqh335sga5ezj@jrouhaud
This commit is contained in:
@ -1985,6 +1985,34 @@ icu_set_collation_attributes(UCollator *collator, const char *loc)
|
||||
|
||||
#endif /* USE_ICU */
|
||||
|
||||
/*
|
||||
* Check if the given locale ID is valid, and ereport(ERROR) if it isn't.
|
||||
*/
|
||||
void
|
||||
check_icu_locale(const char *icu_locale)
|
||||
{
|
||||
#ifdef USE_ICU
|
||||
UCollator *collator;
|
||||
UErrorCode status;
|
||||
|
||||
status = U_ZERO_ERROR;
|
||||
collator = ucol_open(icu_locale, &status);
|
||||
if (U_FAILURE(status))
|
||||
ereport(ERROR,
|
||||
(errmsg("could not open collator for locale \"%s\": %s",
|
||||
icu_locale, u_errorName(status))));
|
||||
|
||||
if (U_ICU_VERSION_MAJOR_NUM < 54)
|
||||
icu_set_collation_attributes(collator, icu_locale);
|
||||
ucol_close(collator);
|
||||
#else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("ICU is not supported in this build"), \
|
||||
errhint("You need to rebuild PostgreSQL using %s.", "--with-icu")));
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* These functions convert from/to libc's wchar_t, *not* pg_wchar_t.
|
||||
* Therefore we keep them here rather than with the mbutils code.
|
||||
|
Reference in New Issue
Block a user