Skip to content

Commit 8b87e92

Browse files
committed
Fix t_isspace(), etc., when datlocprovider=i and datctype=C.
Check whether the datctype is C to determine whether t_isspace() and related functions use isspace() or iswspace(). Previously, t_isspace() checked whether the database default collation was C; which is incorrect when the default collation uses the ICU provider. Discussion: https://postgr.es/m/79e4354d9eccfdb00483146a6b9f6295202e7890.camel@j-davis.com Reviewed-by: Peter Eisentraut Backpatch-through: 15
1 parent 2b216da commit 8b87e92

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

src/backend/tsearch/ts_locale.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@ t_isdigit(const char *ptr)
3838
{
3939
int clen = pg_mblen(ptr);
4040
wchar_t character[WC_BUF_LEN];
41-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
4241
pg_locale_t mylocale = 0; /* TODO */
4342

44-
if (clen == 1 || lc_ctype_is_c(collation))
43+
if (clen == 1 || database_ctype_is_c)
4544
return isdigit(TOUCHAR(ptr));
4645

4746
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
@@ -54,10 +53,9 @@ t_isspace(const char *ptr)
5453
{
5554
int clen = pg_mblen(ptr);
5655
wchar_t character[WC_BUF_LEN];
57-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
5856
pg_locale_t mylocale = 0; /* TODO */
5957

60-
if (clen == 1 || lc_ctype_is_c(collation))
58+
if (clen == 1 || database_ctype_is_c)
6159
return isspace(TOUCHAR(ptr));
6260

6361
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
@@ -70,10 +68,9 @@ t_isalpha(const char *ptr)
7068
{
7169
int clen = pg_mblen(ptr);
7270
wchar_t character[WC_BUF_LEN];
73-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
7471
pg_locale_t mylocale = 0; /* TODO */
7572

76-
if (clen == 1 || lc_ctype_is_c(collation))
73+
if (clen == 1 || database_ctype_is_c)
7774
return isalpha(TOUCHAR(ptr));
7875

7976
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
@@ -86,10 +83,9 @@ t_isprint(const char *ptr)
8683
{
8784
int clen = pg_mblen(ptr);
8885
wchar_t character[WC_BUF_LEN];
89-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
9086
pg_locale_t mylocale = 0; /* TODO */
9187

92-
if (clen == 1 || lc_ctype_is_c(collation))
88+
if (clen == 1 || database_ctype_is_c)
9389
return isprint(TOUCHAR(ptr));
9490

9591
char2wchar(character, WC_BUF_LEN, ptr, clen, mylocale);
@@ -257,7 +253,6 @@ char *
257253
lowerstr_with_len(const char *str, int len)
258254
{
259255
char *out;
260-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
261256
pg_locale_t mylocale = 0; /* TODO */
262257

263258
if (len == 0)
@@ -269,7 +264,7 @@ lowerstr_with_len(const char *str, int len)
269264
* Also, for a C locale there is no need to process as multibyte. From
270265
* backend/utils/adt/oracle_compat.c Teodor
271266
*/
272-
if (pg_database_encoding_max_length() > 1 && !lc_ctype_is_c(collation))
267+
if (pg_database_encoding_max_length() > 1 && !database_ctype_is_c)
273268
{
274269
wchar_t *wstr,
275270
*wptr;

src/backend/tsearch/wparser_def.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,10 @@ TParserInit(char *str, int len)
297297
*/
298298
if (prs->charmaxlen > 1)
299299
{
300-
Oid collation = DEFAULT_COLLATION_OID; /* TODO */
301300
pg_locale_t mylocale = 0; /* TODO */
302301

303302
prs->usewide = true;
304-
if (lc_ctype_is_c(collation))
303+
if (database_ctype_is_c)
305304
{
306305
/*
307306
* char2wchar doesn't work for C-locale and sizeof(pg_wchar) could

src/backend/utils/adt/pg_locale.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ char *localized_full_days[7 + 1];
9999
char *localized_abbrev_months[12 + 1];
100100
char *localized_full_months[12 + 1];
101101

102+
/* is the databases's LC_CTYPE the C locale? */
103+
bool database_ctype_is_c = false;
104+
102105
/* indicates whether locale information cache is valid */
103106
static bool CurrentLocaleConvValid = false;
104107
static bool CurrentLCTimeValid = false;

src/backend/utils/init/postinit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,10 @@ CheckMyDatabase(const char *name, bool am_superuser, bool override_allow_connect
418418
" which is not recognized by setlocale().", ctype),
419419
errhint("Recreate the database with another locale or install the missing locale.")));
420420

421+
if (strcmp(ctype, "C") == 0 ||
422+
strcmp(ctype, "POSIX") == 0)
423+
database_ctype_is_c = true;
424+
421425
if (dbform->datlocprovider == COLLPROVIDER_ICU)
422426
{
423427
datum = SysCacheGetAttr(DATABASEOID, tup, Anum_pg_database_daticulocale, &isnull);

src/include/utils/pg_locale.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ extern PGDLLIMPORT char *localized_full_days[];
4949
extern PGDLLIMPORT char *localized_abbrev_months[];
5050
extern PGDLLIMPORT char *localized_full_months[];
5151

52+
/* is the databases's LC_CTYPE the C locale? */
53+
extern PGDLLIMPORT bool database_ctype_is_c;
5254

5355
extern bool check_locale_messages(char **newval, void **extra, GucSource source);
5456
extern void assign_locale_messages(const char *newval, void *extra);

0 commit comments

Comments
 (0)