aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pg_locale.c
diff options
context:
space:
mode:
authorJeff Davis <jdavis@postgresql.org>2024-08-05 18:15:57 -0700
committerJeff Davis <jdavis@postgresql.org>2024-08-05 18:31:48 -0700
commite9931bfb7515b253cc26ff495ee917acff8995d0 (patch)
tree63e10efac543b3117b032c3993fe9711592a8168 /src/backend/utils/adt/pg_locale.c
parentf80b09bac87d6b49f5dbb6131da5fbd9b9773c5c (diff)
downloadpostgresql-e9931bfb7515b253cc26ff495ee917acff8995d0.tar.gz
postgresql-e9931bfb7515b253cc26ff495ee917acff8995d0.zip
Remove support for null pg_locale_t most places.
Previously, passing NULL for pg_locale_t meant "use the libc provider and the server environment". Now that the database collation is represented as a proper pg_locale_t (not dependent on setlocale()), remove special cases for NULL. Leave wchar2char() and char2wchar() unchanged for now, because the callers don't always have a libc-based pg_locale_t available. Discussion: https://postgr.es/m/cfd9eb85-c52a-4ec9-a90e-a5e4de56e57d@eisentraut.org Reviewed-by: Peter Eisentraut, Andreas Karlsson
Diffstat (limited to 'src/backend/utils/adt/pg_locale.c')
-rw-r--r--src/backend/utils/adt/pg_locale.c73
1 files changed, 28 insertions, 45 deletions
diff --git a/src/backend/utils/adt/pg_locale.c b/src/backend/utils/adt/pg_locale.c
index 02f64f957d1..4e076904585 100644
--- a/src/backend/utils/adt/pg_locale.c
+++ b/src/backend/utils/adt/pg_locale.c
@@ -1464,11 +1464,7 @@ make_icu_collator(const char *iculocstr,
bool
pg_locale_deterministic(pg_locale_t locale)
{
- /* default locale must always be deterministic */
- if (locale == NULL)
- return true;
- else
- return locale->deterministic;
+ return locale->deterministic;
}
/*
@@ -1812,7 +1808,7 @@ get_collation_actual_version(char collprovider, const char *collcollate)
* pg_strncoll_libc_win32_utf8
*
* Win32 does not have UTF-8. Convert UTF8 arguments to wide characters and
- * invoke wcscoll() or wcscoll_l().
+ * invoke wcscoll_l().
*/
#ifdef WIN32
static int
@@ -1828,7 +1824,7 @@ pg_strncoll_libc_win32_utf8(const char *arg1, size_t len1, const char *arg2,
int r;
int result;
- Assert(!locale || locale->provider == COLLPROVIDER_LIBC);
+ Assert(locale->provider == COLLPROVIDER_LIBC);
Assert(GetDatabaseEncoding() == PG_UTF8);
#ifndef WIN32
Assert(false);
@@ -1868,10 +1864,7 @@ pg_strncoll_libc_win32_utf8(const char *arg1, size_t len1, const char *arg2,
((LPWSTR) a2p)[r] = 0;
errno = 0;
- if (locale)
- result = wcscoll_l((LPWSTR) a1p, (LPWSTR) a2p, locale->info.lt);
- else
- result = wcscoll((LPWSTR) a1p, (LPWSTR) a2p);
+ result = wcscoll_l((LPWSTR) a1p, (LPWSTR) a2p, locale->info.lt);
if (result == 2147483647) /* _NLSCMPERROR; missing from mingw headers */
ereport(ERROR,
(errmsg("could not compare Unicode strings: %m")));
@@ -1886,9 +1879,9 @@ pg_strncoll_libc_win32_utf8(const char *arg1, size_t len1, const char *arg2,
/*
* pg_strcoll_libc
*
- * Call strcoll(), strcoll_l(), wcscoll(), or wcscoll_l() as appropriate for
- * the given locale, platform, and database encoding. If the locale is NULL,
- * use the database collation.
+ * Call strcoll_l() or wcscoll_l() as appropriate for the given locale,
+ * platform, and database encoding. If the locale is NULL, use the database
+ * collation.
*
* Arguments must be encoded in the database encoding and nul-terminated.
*/
@@ -1897,7 +1890,7 @@ pg_strcoll_libc(const char *arg1, const char *arg2, pg_locale_t locale)
{
int result;
- Assert(!locale || locale->provider == COLLPROVIDER_LIBC);
+ Assert(locale->provider == COLLPROVIDER_LIBC);
#ifdef WIN32
if (GetDatabaseEncoding() == PG_UTF8)
{
@@ -1908,10 +1901,7 @@ pg_strcoll_libc(const char *arg1, const char *arg2, pg_locale_t locale)
}
else
#endif /* WIN32 */
- if (locale)
result = strcoll_l(arg1, arg2, locale->info.lt);
- else
- result = strcoll(arg1, arg2);
return result;
}
@@ -1933,7 +1923,7 @@ pg_strncoll_libc(const char *arg1, size_t len1, const char *arg2, size_t len2,
char *arg2n;
int result;
- Assert(!locale || locale->provider == COLLPROVIDER_LIBC);
+ Assert(locale->provider == COLLPROVIDER_LIBC);
#ifdef WIN32
/* check for this case before doing the work for nul-termination */
@@ -2064,9 +2054,9 @@ pg_strncoll_icu(const char *arg1, int32_t len1, const char *arg2, int32_t len2,
/*
* pg_strcoll
*
- * Call ucol_strcollUTF8(), ucol_strcoll(), strcoll(), strcoll_l(), wcscoll(),
- * or wcscoll_l() as appropriate for the given locale, platform, and database
- * encoding. If the locale is not specified, use the database collation.
+ * Call ucol_strcollUTF8(), ucol_strcoll(), strcoll_l() or wcscoll_l() as
+ * appropriate for the given locale, platform, and database encoding. If the
+ * locale is not specified, use the database collation.
*
* Arguments must be encoded in the database encoding and nul-terminated.
*
@@ -2079,7 +2069,7 @@ pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
{
int result;
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
result = pg_strcoll_libc(arg1, arg2, locale);
#ifdef USE_ICU
else if (locale->provider == COLLPROVIDER_ICU)
@@ -2095,9 +2085,9 @@ pg_strcoll(const char *arg1, const char *arg2, pg_locale_t locale)
/*
* pg_strncoll
*
- * Call ucol_strcollUTF8(), ucol_strcoll(), strcoll(), strcoll_l(), wcscoll(),
- * or wcscoll_l() as appropriate for the given locale, platform, and database
- * encoding. If the locale is not specified, use the database collation.
+ * Call ucol_strcollUTF8(), ucol_strcoll(), strcoll_l() or wcscoll_l() as
+ * appropriate for the given locale, platform, and database encoding. If the
+ * locale is not specified, use the database collation.
*
* Arguments must be encoded in the database encoding.
*
@@ -2115,7 +2105,7 @@ pg_strncoll(const char *arg1, size_t len1, const char *arg2, size_t len2,
{
int result;
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
result = pg_strncoll_libc(arg1, len1, arg2, len2, locale);
#ifdef USE_ICU
else if (locale->provider == COLLPROVIDER_ICU)
@@ -2133,13 +2123,10 @@ static size_t
pg_strxfrm_libc(char *dest, const char *src, size_t destsize,
pg_locale_t locale)
{
- Assert(!locale || locale->provider == COLLPROVIDER_LIBC);
+ Assert(locale->provider == COLLPROVIDER_LIBC);
#ifdef TRUST_STRXFRM
- if (locale)
- return strxfrm_l(dest, src, destsize, locale->info.lt);
- else
- return strxfrm(dest, src, destsize);
+ return strxfrm_l(dest, src, destsize, locale->info.lt);
#else
/* shouldn't happen */
PGLOCALE_SUPPORT_ERROR(locale->provider);
@@ -2156,7 +2143,7 @@ pg_strnxfrm_libc(char *dest, const char *src, size_t srclen, size_t destsize,
size_t bufsize = srclen + 1;
size_t result;
- Assert(!locale || locale->provider == COLLPROVIDER_LIBC);
+ Assert(locale->provider == COLLPROVIDER_LIBC);
if (bufsize > TEXTBUFLEN)
buf = palloc(bufsize);
@@ -2328,7 +2315,7 @@ pg_strnxfrm_prefix_icu(char *dest, const char *src, int32_t srclen,
bool
pg_strxfrm_enabled(pg_locale_t locale)
{
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
#ifdef TRUST_STRXFRM
return true;
#else
@@ -2362,7 +2349,7 @@ pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
{
size_t result = 0; /* keep compiler quiet */
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
result = pg_strxfrm_libc(dest, src, destsize, locale);
#ifdef USE_ICU
else if (locale->provider == COLLPROVIDER_ICU)
@@ -2399,7 +2386,7 @@ pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen,
{
size_t result = 0; /* keep compiler quiet */
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
result = pg_strnxfrm_libc(dest, src, srclen, destsize, locale);
#ifdef USE_ICU
else if (locale->provider == COLLPROVIDER_ICU)
@@ -2419,7 +2406,7 @@ pg_strnxfrm(char *dest, size_t destsize, const char *src, size_t srclen,
bool
pg_strxfrm_prefix_enabled(pg_locale_t locale)
{
- if (!locale || locale->provider == COLLPROVIDER_LIBC)
+ if (locale->provider == COLLPROVIDER_LIBC)
return false;
else if (locale->provider == COLLPROVIDER_ICU)
return true;
@@ -2449,13 +2436,11 @@ pg_strxfrm_prefix(char *dest, const char *src, size_t destsize,
{
size_t result = 0; /* keep compiler quiet */
- if (!locale)
- PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
#ifdef USE_ICU
- else if (locale->provider == COLLPROVIDER_ICU)
+ if (locale->provider == COLLPROVIDER_ICU)
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
-#endif
else
+#endif
PGLOCALE_SUPPORT_ERROR(locale->provider);
return result;
@@ -2484,13 +2469,11 @@ pg_strnxfrm_prefix(char *dest, size_t destsize, const char *src,
{
size_t result = 0; /* keep compiler quiet */
- if (!locale)
- PGLOCALE_SUPPORT_ERROR(COLLPROVIDER_LIBC);
#ifdef USE_ICU
- else if (locale->provider == COLLPROVIDER_ICU)
+ if (locale->provider == COLLPROVIDER_ICU)
result = pg_strnxfrm_prefix_icu(dest, src, -1, destsize, locale);
-#endif
else
+#endif
PGLOCALE_SUPPORT_ERROR(locale->provider);
return result;