Skip to content

Commit 53cd0b7

Browse files
committed
Change wchar2char() and char2wchar() to accept a locale_t.
These are libc-specific functions, so should require a locale_t rather than a pg_locale_t (which could use another provider). Discussion: https://postgr.es/m/a8666c391dfcabe79868d95f7160eac533ace718.camel%40j-davis.com
1 parent 9dcc764 commit 53cd0b7

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/backend/tsearch/ts_locale.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ t_isalpha(const char *ptr)
3636
{
3737
int clen = pg_mblen(ptr);
3838
wchar_t character[WC_BUF_LEN];
39-
pg_locale_t mylocale = 0; /* TODO */
39+
locale_t mylocale = 0; /* TODO */
4040

4141
if (clen == 1 || database_ctype_is_c)
4242
return isalpha(TOUCHAR(ptr));
@@ -51,7 +51,7 @@ t_isalnum(const char *ptr)
5151
{
5252
int clen = pg_mblen(ptr);
5353
wchar_t character[WC_BUF_LEN];
54-
pg_locale_t mylocale = 0; /* TODO */
54+
locale_t mylocale = 0; /* TODO */
5555

5656
if (clen == 1 || database_ctype_is_c)
5757
return isalnum(TOUCHAR(ptr));

src/backend/tsearch/wparser_def.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ TParserInit(char *str, int len)
299299
*/
300300
if (prs->charmaxlen > 1)
301301
{
302-
pg_locale_t mylocale = 0; /* TODO */
302+
locale_t mylocale = 0; /* TODO */
303303

304304
prs->usewide = true;
305305
if (database_ctype_is_c)

src/backend/utils/adt/pg_locale_libc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
457457
/* Output workspace cannot have more codes than input bytes */
458458
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
459459

460-
char2wchar(workspace, srclen + 1, src, srclen, locale);
460+
char2wchar(workspace, srclen + 1, src, srclen, loc);
461461

462462
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
463463
workspace[curr_char] = towlower_l(workspace[curr_char], loc);
@@ -468,7 +468,7 @@ strlower_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
468468
max_size = curr_char * pg_database_encoding_max_length();
469469
result = palloc(max_size + 1);
470470

471-
result_size = wchar2char(result, workspace, max_size + 1, locale);
471+
result_size = wchar2char(result, workspace, max_size + 1, loc);
472472

473473
if (result_size + 1 > destsize)
474474
return result_size;
@@ -552,7 +552,7 @@ strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
552552
/* Output workspace cannot have more codes than input bytes */
553553
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
554554

555-
char2wchar(workspace, srclen + 1, src, srclen, locale);
555+
char2wchar(workspace, srclen + 1, src, srclen, loc);
556556

557557
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
558558
{
@@ -569,7 +569,7 @@ strtitle_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
569569
max_size = curr_char * pg_database_encoding_max_length();
570570
result = palloc(max_size + 1);
571571

572-
result_size = wchar2char(result, workspace, max_size + 1, locale);
572+
result_size = wchar2char(result, workspace, max_size + 1, loc);
573573

574574
if (result_size + 1 > destsize)
575575
return result_size;
@@ -640,7 +640,7 @@ strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
640640
/* Output workspace cannot have more codes than input bytes */
641641
workspace = (wchar_t *) palloc((srclen + 1) * sizeof(wchar_t));
642642

643-
char2wchar(workspace, srclen + 1, src, srclen, locale);
643+
char2wchar(workspace, srclen + 1, src, srclen, loc);
644644

645645
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
646646
workspace[curr_char] = towupper_l(workspace[curr_char], loc);
@@ -651,7 +651,7 @@ strupper_libc_mb(char *dest, size_t destsize, const char *src, ssize_t srclen,
651651
max_size = curr_char * pg_database_encoding_max_length();
652652
result = palloc(max_size + 1);
653653

654-
result_size = wchar2char(result, workspace, max_size + 1, locale);
654+
result_size = wchar2char(result, workspace, max_size + 1, loc);
655655

656656
if (result_size + 1 > destsize)
657657
return result_size;
@@ -1130,7 +1130,7 @@ wcstombs_l(char *dest, const wchar_t *src, size_t n, locale_t loc)
11301130
* zero-terminated. The output will be zero-terminated iff there is room.
11311131
*/
11321132
size_t
1133-
wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
1133+
wchar2char(char *to, const wchar_t *from, size_t tolen, locale_t loc)
11341134
{
11351135
size_t result;
11361136

@@ -1160,15 +1160,15 @@ wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
11601160
}
11611161
else
11621162
#endif /* WIN32 */
1163-
if (locale == (pg_locale_t) 0)
1163+
if (loc == (locale_t) 0)
11641164
{
11651165
/* Use wcstombs directly for the default locale */
11661166
result = wcstombs(to, from, tolen);
11671167
}
11681168
else
11691169
{
11701170
/* Use wcstombs_l for nondefault locales */
1171-
result = wcstombs_l(to, from, tolen, locale->info.lt);
1171+
result = wcstombs_l(to, from, tolen, loc);
11721172
}
11731173

11741174
return result;
@@ -1185,7 +1185,7 @@ wchar2char(char *to, const wchar_t *from, size_t tolen, pg_locale_t locale)
11851185
*/
11861186
size_t
11871187
char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
1188-
pg_locale_t locale)
1188+
locale_t loc)
11891189
{
11901190
size_t result;
11911191

@@ -1220,15 +1220,15 @@ char2wchar(wchar_t *to, size_t tolen, const char *from, size_t fromlen,
12201220
/* mbstowcs requires ending '\0' */
12211221
char *str = pnstrdup(from, fromlen);
12221222

1223-
if (locale == (pg_locale_t) 0)
1223+
if (loc == (locale_t) 0)
12241224
{
12251225
/* Use mbstowcs directly for the default locale */
12261226
result = mbstowcs(to, str, tolen);
12271227
}
12281228
else
12291229
{
12301230
/* Use mbstowcs_l for nondefault locales */
1231-
result = mbstowcs_l(to, str, tolen, locale->info.lt);
1231+
result = mbstowcs_l(to, str, tolen, loc);
12321232
}
12331233

12341234
pfree(str);

src/include/utils/pg_locale.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ extern void report_newlocale_failure(const char *localename);
214214

215215
/* These functions convert from/to libc's wchar_t, *not* pg_wchar_t */
216216
extern size_t wchar2char(char *to, const wchar_t *from, size_t tolen,
217-
pg_locale_t locale);
217+
locale_t loc);
218218
extern size_t char2wchar(wchar_t *to, size_t tolen,
219-
const char *from, size_t fromlen, pg_locale_t locale);
219+
const char *from, size_t fromlen, locale_t loc);
220220

221221
#endif /* _PG_LOCALE_ */

0 commit comments

Comments
 (0)