From e9f4ac1389d9fe6b996937e5d308f5ec462cf69a Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 5 Aug 2017 11:48:32 -0400 Subject: [PATCH] Suppress unused-variable warnings when building with ICU 4.2. Tidy-up for commit eccead9ed. --- src/backend/commands/collationcmds.c | 33 +++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index ea257a3786..ed5ffb6594 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -678,14 +678,30 @@ pg_import_system_collations(PG_FUNCTION_ARGS) */ for (i = -1; i < ucol_countAvailable(); i++) { + /* + * In ICU 4.2, ucol_getKeywordsForLocale() sometimes returns + * values that will not be accepted by uloc_toLanguageTag(). Skip + * loading keyword variants in that version. (Both + * ucol_getKeywordValuesForLocale() and uloc_toLanguageTag() are + * new in ICU 4.2, so older versions are not supported at all.) + * + * XXX We have no information about ICU 4.3 through 4.7, but we + * know the code below works with 4.8. + */ +#if U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM > 2) +#define LOAD_ICU_KEYWORD_VARIANTS +#endif + const char *name; char *langtag; char *icucomment; const char *collcollate; + Oid collid; +#ifdef LOAD_ICU_KEYWORD_VARIANTS UEnumeration *en; UErrorCode status; const char *val; - Oid collid; +#endif if (i == -1) name = ""; /* ICU root locale */ @@ -721,18 +737,9 @@ pg_import_system_collations(PG_FUNCTION_ARGS) } /* - * Add keyword variants - * - * In ICU 4.2, ucol_getKeywordsForLocale() sometimes returns - * values that will not be accepted by uloc_toLanguageTag(). Skip - * loading keyword variants in that version. (Both - * ucol_getKeywordValuesForLocale() and uloc_toLanguageTag() are - * new in ICU 4.2, so older versions are not supported at all.) - * - * XXX We have no information about ICU 4.3 through 4.7, but we - * know the below works with 4.8. + * Add keyword variants, if enabled. */ -#if U_ICU_VERSION_MAJOR_NUM > 4 || (U_ICU_VERSION_MAJOR_NUM == 4 && U_ICU_VERSION_MINOR_NUM > 2) +#ifdef LOAD_ICU_KEYWORD_VARIANTS status = U_ZERO_ERROR; en = ucol_getKeywordValuesForLocale("collation", name, TRUE, &status); if (U_FAILURE(status)) @@ -779,7 +786,7 @@ pg_import_system_collations(PG_FUNCTION_ARGS) (errmsg("could not get keyword values for locale \"%s\": %s", name, u_errorName(status)))); uenum_close(en); -#endif /* ICU >4.2 */ +#endif /* LOAD_ICU_KEYWORD_VARIANTS */ } } #endif /* USE_ICU */ -- 2.40.0