v2-0006-tsearch-use-global_libc_locale.patch
text/x-patch
Filename: v2-0006-tsearch-use-global_libc_locale.patch
Type: text/x-patch
Part: 5
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v2-0006
Subject: tsearch: use global_libc_locale.
| File | + | − |
|---|---|---|
| configure | 1 | 1 |
| configure.ac | 2 | 0 |
| meson.build | 2 | 0 |
| src/backend/tsearch/ts_locale.c | 4 | 4 |
| src/backend/tsearch/wparser_def.c | 40 | 4 |
| src/include/pg_config.h.in | 6 | 0 |
From 229d9ec22a6c8dc50a709ae5032896e7932d219b Mon Sep 17 00:00:00 2001
From: Jeff Davis <jeff@j-davis.com>
Date: Wed, 11 Jun 2025 10:07:29 -0700
Subject: [PATCH v2 6/7] tsearch: use global_libc_locale.
---
configure | 2 +-
configure.ac | 2 ++
meson.build | 2 ++
src/backend/tsearch/ts_locale.c | 8 +++---
src/backend/tsearch/wparser_def.c | 44 ++++++++++++++++++++++++++++---
src/include/pg_config.h.in | 6 +++++
6 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/configure b/configure
index 4f15347cc95..2660c29e0d2 100755
--- a/configure
+++ b/configure
@@ -15616,7 +15616,7 @@ fi
LIBS_including_readline="$LIBS"
LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
-for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
+for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton iswxdigit_l isxdigit_l kqueue localeconv_l mbstowcs_l posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
diff --git a/configure.ac b/configure.ac
index 4b8335dc613..2d16c5fd43f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1789,6 +1789,8 @@ AC_CHECK_FUNCS(m4_normalize([
getifaddrs
getpeerucred
inet_pton
+ iswxdigit_l
+ isxdigit_l
kqueue
localeconv_l
mbstowcs_l
diff --git a/meson.build b/meson.build
index d142e3e408b..0bd6f9f2076 100644
--- a/meson.build
+++ b/meson.build
@@ -2880,6 +2880,8 @@ func_checks = [
['getpeerucred'],
['inet_aton'],
['inet_pton'],
+ ['iswxdigit_l'],
+ ['isxdigit_l'],
['kqueue'],
['localeconv_l'],
['mbstowcs_l'],
diff --git a/src/backend/tsearch/ts_locale.c b/src/backend/tsearch/ts_locale.c
index 4801fe90089..6b66fd1c05b 100644
--- a/src/backend/tsearch/ts_locale.c
+++ b/src/backend/tsearch/ts_locale.c
@@ -36,14 +36,14 @@ t_isalpha(const char *ptr)
{
int clen = pg_mblen(ptr);
wchar_t character[WC_BUF_LEN];
- locale_t mylocale = 0; /* TODO */
+ locale_t mylocale = global_libc_locale; /* TODO */
if (clen == 1 || database_ctype_is_c)
return isalpha(TOUCHAR(ptr));
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
- return iswalpha((wint_t) character[0]);
+ return iswalpha_l((wint_t) character[0], mylocale);
}
int
@@ -51,14 +51,14 @@ t_isalnum(const char *ptr)
{
int clen = pg_mblen(ptr);
wchar_t character[WC_BUF_LEN];
- locale_t mylocale = 0; /* TODO */
+ locale_t mylocale = global_libc_locale; /* TODO */
if (clen == 1 || database_ctype_is_c)
return isalnum(TOUCHAR(ptr));
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
- return iswalnum((wint_t) character[0]);
+ return iswalnum_l((wint_t) character[0], mylocale);
}
diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c
index e2dd3da3aa3..9a80d32b448 100644
--- a/src/backend/tsearch/wparser_def.c
+++ b/src/backend/tsearch/wparser_def.c
@@ -299,7 +299,7 @@ TParserInit(char *str, int len)
*/
if (prs->charmaxlen > 1)
{
- locale_t mylocale = 0; /* TODO */
+ locale_t mylocale = global_libc_locale; /* TODO */
prs->usewide = true;
if (database_ctype_is_c)
@@ -411,6 +411,40 @@ TParserCopyClose(TParser *prs)
}
+#ifndef HAVE_ISXDIGIT_L
+static int
+isxdigit_l(wint_t wc, locale_t loc)
+{
+#ifdef WIN32
+ return _isxdigit_l(wc, loc);
+#else
+ size_t result;
+ locale_t save_locale = uselocale(loc);
+
+ result = isxdigit(wc);
+ uselocale(save_locale);
+ return result;
+#endif
+}
+#endif
+#ifndef HAVE_ISWXDIGIT_L
+static int
+iswxdigit_l(wint_t wc, locale_t loc)
+{
+#ifdef WIN32
+ return _iswxdigit_l(wc, loc);
+#else
+ size_t result;
+ locale_t save_locale = uselocale(loc);
+
+ result = iswxdigit(wc);
+ uselocale(save_locale);
+ return result;
+#endif
+}
+#endif
+
+
/*
* Character-type support functions, equivalent to is* macros, but
* working with any possible encodings and locales. Notes:
@@ -434,11 +468,13 @@ p_is##type(TParser *prs) \
unsigned int c = *(prs->pgwstr + prs->state->poschar); \
if (c > 0x7f) \
return nonascii; \
- return is##type(c); \
+ return is##type##_l(c, global_libc_locale); \
} \
- return isw##type(*(prs->wstr + prs->state->poschar)); \
+ return isw##type##_l(*(prs->wstr + prs->state->poschar), \
+ global_libc_locale); \
} \
- return is##type(*(unsigned char *) (prs->str + prs->state->posbyte)); \
+ return is##type##_l(*(unsigned char *) (prs->str + prs->state->posbyte), \
+ global_libc_locale); \
} \
\
static int \
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index 726a7c1be1f..f06396c94f4 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -229,6 +229,12 @@
/* Define to 1 if you have the global variable 'int timezone'. */
#undef HAVE_INT_TIMEZONE
+/* Define to 1 if you have the `iswxdigit_l' function. */
+#undef HAVE_ISWXDIGIT_L
+
+/* Define to 1 if you have the `isxdigit_l' function. */
+#undef HAVE_ISXDIGIT_L
+
/* Define to 1 if __builtin_constant_p(x) implies "i"(x) acceptance. */
#undef HAVE_I_CONSTRAINT__BUILTIN_CONSTANT_P
--
2.43.0