From: Jeff Davis Date: Wed, 7 Jan 2026 01:19:51 +0000 (-0800) Subject: Clean up ICU includes. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af2d4ca191a4552217eceace21fde6ebc2b85770;p=thirdparty%2Fpostgresql.git Clean up ICU includes. Remove ICU includes from pg_locale.h, and instead include them in the few C files that need ICU. Clean up a few other includes in passing. Reviewed-by: Andres Freund Discussion: https://postgr.es/m/48911db71d953edec66df0d2ce303563d631fbe0.camel@j-davis.com --- diff --git a/src/backend/commands/collationcmds.c b/src/backend/commands/collationcmds.c index 8f3dddc619e..980cc3ac627 100644 --- a/src/backend/commands/collationcmds.c +++ b/src/backend/commands/collationcmds.c @@ -14,6 +14,10 @@ */ #include "postgres.h" +#ifdef USE_ICU +#include +#endif + #include "access/htup_details.h" #include "access/table.h" #include "access/xact.h" diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c index f5f4a110e12..6affdd86624 100644 --- a/src/backend/utils/adt/formatting.c +++ b/src/backend/utils/adt/formatting.c @@ -68,17 +68,9 @@ #include #include #include -#include -#ifdef USE_ICU -#include -#endif - -#include "catalog/pg_collation.h" #include "catalog/pg_type.h" #include "common/int.h" -#include "common/unicode_case.h" -#include "common/unicode_category.h" #include "mb/pg_wchar.h" #include "nodes/miscnodes.h" #include "parser/scansup.h" diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c index 9a92f2fc959..ac324ecaad2 100644 --- a/src/backend/utils/adt/pg_locale.c +++ b/src/backend/utils/adt/pg_locale.c @@ -32,6 +32,9 @@ #include "postgres.h" #include +#ifdef USE_ICU +#include +#endif #include "access/htup_details.h" #include "catalog/pg_collation.h" @@ -1645,6 +1648,17 @@ pg_towlower(pg_wchar wc, pg_locale_t locale) return locale->ctype->wc_tolower(wc, locale); } +/* version of Unicode used by ICU */ +const char * +pg_icu_unicode_version() +{ +#ifdef USE_ICU + return U_UNICODE_VERSION; +#else + return NULL; +#endif +} + /* * Return required encoding ID for the given locale, or -1 if any encoding is * valid for the locale. diff --git a/src/backend/utils/adt/pg_locale_icu.c b/src/backend/utils/adt/pg_locale_icu.c index 68491666738..88f86ab18a3 100644 --- a/src/backend/utils/adt/pg_locale_icu.c +++ b/src/backend/utils/adt/pg_locale_icu.c @@ -12,7 +12,9 @@ #include "postgres.h" #ifdef USE_ICU +#include #include +#include #include /* diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index cfcc35592e3..c80191f0a22 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -5381,11 +5381,12 @@ unicode_version(PG_FUNCTION_ARGS) Datum icu_unicode_version(PG_FUNCTION_ARGS) { -#ifdef USE_ICU - PG_RETURN_TEXT_P(cstring_to_text(U_UNICODE_VERSION)); -#else - PG_RETURN_NULL(); -#endif + const char *version = pg_icu_unicode_version(); + + if (version) + PG_RETURN_TEXT_P(cstring_to_text(version)); + else + PG_RETURN_NULL(); } /* diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h index 465f170ba79..444350bb803 100644 --- a/src/include/utils/pg_locale.h +++ b/src/include/utils/pg_locale.h @@ -14,16 +14,6 @@ #include "mb/pg_wchar.h" -#ifdef USE_ICU -/* only include the C APIs, to avoid errors in cpluspluscheck */ -#undef U_SHOW_CPLUSPLUS_API -#define U_SHOW_CPLUSPLUS_API 0 -#undef U_SHOW_CPLUSPLUS_HEADER_API -#define U_SHOW_CPLUSPLUS_HEADER_API 0 -#include -#include -#endif - /* use for libc locale names */ #define LOCALE_NAME_BUFLEN 128 @@ -167,9 +157,9 @@ struct pg_locale_struct struct { const char *locale; - UCollator *ucol; + struct UCollator *ucol; + struct UCaseMap *ucasemap; locale_t lt; - UCaseMap *ucasemap; } icu; #endif }; @@ -223,6 +213,8 @@ extern bool pg_iswcased(pg_wchar wc, pg_locale_t locale); extern pg_wchar pg_towupper(pg_wchar wc, pg_locale_t locale); extern pg_wchar pg_towlower(pg_wchar wc, pg_locale_t locale); +extern const char *pg_icu_unicode_version(void); + extern int builtin_locale_encoding(const char *locale); extern const char *builtin_validate_locale(int encoding, const char *locale); extern void icu_validate_locale(const char *loc_str);