]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Clean up ICU includes.
authorJeff Davis <jdavis@postgresql.org>
Wed, 7 Jan 2026 01:19:51 +0000 (17:19 -0800)
committerJeff Davis <jdavis@postgresql.org>
Wed, 7 Jan 2026 01:19:51 +0000 (17:19 -0800)
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 <andres@anarazel.de>
Discussion: https://postgr.es/m/48911db71d953edec66df0d2ce303563d631fbe0.camel@j-davis.com

src/backend/commands/collationcmds.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/pg_locale_icu.c
src/backend/utils/adt/varlena.c
src/include/utils/pg_locale.h

index 8f3dddc619e3538326da9e7ac472bd3b6baf1126..980cc3ac62758ad8c808f2e9f89e50d8cec8b168 100644 (file)
  */
 #include "postgres.h"
 
+#ifdef USE_ICU
+#include <unicode/uloc.h>
+#endif
+
 #include "access/htup_details.h"
 #include "access/table.h"
 #include "access/xact.h"
index f5f4a110e12f1dea495221364564c33dfd4d8d12..6affdd866246e58fc3e12563e952bc645c662ec2 100644 (file)
 #include <math.h>
 #include <float.h>
 #include <limits.h>
-#include <wctype.h>
 
-#ifdef USE_ICU
-#include <unicode/ustring.h>
-#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"
index 9a92f2fc959a244f85ed871d2c03753ae78ef93e..ac324ecaad2bd540642ee17accb8b94cffe8928a 100644 (file)
@@ -32,6 +32,9 @@
 #include "postgres.h"
 
 #include <time.h>
+#ifdef USE_ICU
+#include <unicode/ucol.h>
+#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.
index 68491666738e9b6a645912b93cd6c52a80a74ac5..88f86ab18a3980d9e6dc4587362923d3f4709e8d 100644 (file)
@@ -12,7 +12,9 @@
 #include "postgres.h"
 
 #ifdef USE_ICU
+#include <unicode/ucasemap.h>
 #include <unicode/ucnv.h>
+#include <unicode/ucol.h>
 #include <unicode/ustring.h>
 
 /*
index cfcc35592e32a06e9d192fc7262582e26faa9db6..c80191f0a224eb71f135d78f5f77cf2122761f7c 100644 (file)
@@ -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();
 }
 
 /*
index 465f170ba792109d7b3185a668843c9c3c0c7462..444350bb803a9085496e04adcf3ae0a312d2d3c5 100644 (file)
 
 #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 <unicode/ucol.h>
-#include <unicode/ucasemap.h>
-#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);