Skip to content

Commit e9931bf

Browse files
committed
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
1 parent f80b09b commit e9931bf

File tree

7 files changed

+73
-255
lines changed

7 files changed

+73
-255
lines changed

src/backend/access/hash/hashfunc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ hashtext(PG_FUNCTION_ARGS)
268268
{
269269
text *key = PG_GETARG_TEXT_PP(0);
270270
Oid collid = PG_GET_COLLATION();
271-
pg_locale_t mylocale = 0;
271+
pg_locale_t mylocale;
272272
Datum result;
273273

274274
if (!collid)
@@ -277,8 +277,7 @@ hashtext(PG_FUNCTION_ARGS)
277277
errmsg("could not determine which collation to use for string hashing"),
278278
errhint("Use the COLLATE clause to set the collation explicitly.")));
279279

280-
if (!lc_collate_is_c(collid))
281-
mylocale = pg_newlocale_from_collation(collid);
280+
mylocale = pg_newlocale_from_collation(collid);
282281

283282
if (pg_locale_deterministic(mylocale))
284283
{
@@ -324,7 +323,7 @@ hashtextextended(PG_FUNCTION_ARGS)
324323
{
325324
text *key = PG_GETARG_TEXT_PP(0);
326325
Oid collid = PG_GET_COLLATION();
327-
pg_locale_t mylocale = 0;
326+
pg_locale_t mylocale;
328327
Datum result;
329328

330329
if (!collid)
@@ -333,8 +332,7 @@ hashtextextended(PG_FUNCTION_ARGS)
333332
errmsg("could not determine which collation to use for string hashing"),
334333
errhint("Use the COLLATE clause to set the collation explicitly.")));
335334

336-
if (!lc_collate_is_c(collid))
337-
mylocale = pg_newlocale_from_collation(collid);
335+
mylocale = pg_newlocale_from_collation(collid);
338336

339337
if (pg_locale_deterministic(mylocale))
340338
{

src/backend/regex/regc_pg_locale.c

Lines changed: 4 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ typedef enum
6767
{
6868
PG_REGEX_LOCALE_C, /* C locale (encoding independent) */
6969
PG_REGEX_BUILTIN, /* built-in Unicode semantics */
70-
PG_REGEX_LOCALE_WIDE, /* Use <wctype.h> functions */
71-
PG_REGEX_LOCALE_1BYTE, /* Use <ctype.h> functions */
7270
PG_REGEX_LOCALE_WIDE_L, /* Use locale_t <wctype.h> functions */
7371
PG_REGEX_LOCALE_1BYTE_L, /* Use locale_t <ctype.h> functions */
7472
PG_REGEX_LOCALE_ICU, /* Use ICU uchar.h functions */
@@ -261,33 +259,23 @@ pg_set_regex_collation(Oid collation)
261259
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
262260
errmsg("nondeterministic collations are not supported for regular expressions")));
263261

264-
if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
262+
if (pg_regex_locale->provider == COLLPROVIDER_BUILTIN)
265263
{
266264
Assert(GetDatabaseEncoding() == PG_UTF8);
267265
pg_regex_strategy = PG_REGEX_BUILTIN;
268266
}
269267
#ifdef USE_ICU
270-
else if (pg_regex_locale && pg_regex_locale->provider == COLLPROVIDER_ICU)
268+
else if (pg_regex_locale->provider == COLLPROVIDER_ICU)
271269
{
272270
pg_regex_strategy = PG_REGEX_LOCALE_ICU;
273271
}
274272
#endif
275273
else
276274
{
277275
if (GetDatabaseEncoding() == PG_UTF8)
278-
{
279-
if (pg_regex_locale)
280-
pg_regex_strategy = PG_REGEX_LOCALE_WIDE_L;
281-
else
282-
pg_regex_strategy = PG_REGEX_LOCALE_WIDE;
283-
}
276+
pg_regex_strategy = PG_REGEX_LOCALE_WIDE_L;
284277
else
285-
{
286-
if (pg_regex_locale)
287-
pg_regex_strategy = PG_REGEX_LOCALE_1BYTE_L;
288-
else
289-
pg_regex_strategy = PG_REGEX_LOCALE_1BYTE;
290-
}
278+
pg_regex_strategy = PG_REGEX_LOCALE_1BYTE_L;
291279
}
292280

293281
pg_regex_collation = collation;
@@ -304,13 +292,6 @@ pg_wc_isdigit(pg_wchar c)
304292
(pg_char_properties[c] & PG_ISDIGIT));
305293
case PG_REGEX_BUILTIN:
306294
return pg_u_isdigit(c, true);
307-
case PG_REGEX_LOCALE_WIDE:
308-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
309-
return iswdigit((wint_t) c);
310-
/* FALL THRU */
311-
case PG_REGEX_LOCALE_1BYTE:
312-
return (c <= (pg_wchar) UCHAR_MAX &&
313-
isdigit((unsigned char) c));
314295
case PG_REGEX_LOCALE_WIDE_L:
315296
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
316297
return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
@@ -338,13 +319,6 @@ pg_wc_isalpha(pg_wchar c)
338319
(pg_char_properties[c] & PG_ISALPHA));
339320
case PG_REGEX_BUILTIN:
340321
return pg_u_isalpha(c);
341-
case PG_REGEX_LOCALE_WIDE:
342-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
343-
return iswalpha((wint_t) c);
344-
/* FALL THRU */
345-
case PG_REGEX_LOCALE_1BYTE:
346-
return (c <= (pg_wchar) UCHAR_MAX &&
347-
isalpha((unsigned char) c));
348322
case PG_REGEX_LOCALE_WIDE_L:
349323
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
350324
return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
@@ -372,13 +346,6 @@ pg_wc_isalnum(pg_wchar c)
372346
(pg_char_properties[c] & PG_ISALNUM));
373347
case PG_REGEX_BUILTIN:
374348
return pg_u_isalnum(c, true);
375-
case PG_REGEX_LOCALE_WIDE:
376-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
377-
return iswalnum((wint_t) c);
378-
/* FALL THRU */
379-
case PG_REGEX_LOCALE_1BYTE:
380-
return (c <= (pg_wchar) UCHAR_MAX &&
381-
isalnum((unsigned char) c));
382349
case PG_REGEX_LOCALE_WIDE_L:
383350
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
384351
return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
@@ -415,13 +382,6 @@ pg_wc_isupper(pg_wchar c)
415382
(pg_char_properties[c] & PG_ISUPPER));
416383
case PG_REGEX_BUILTIN:
417384
return pg_u_isupper(c);
418-
case PG_REGEX_LOCALE_WIDE:
419-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
420-
return iswupper((wint_t) c);
421-
/* FALL THRU */
422-
case PG_REGEX_LOCALE_1BYTE:
423-
return (c <= (pg_wchar) UCHAR_MAX &&
424-
isupper((unsigned char) c));
425385
case PG_REGEX_LOCALE_WIDE_L:
426386
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
427387
return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
@@ -449,13 +409,6 @@ pg_wc_islower(pg_wchar c)
449409
(pg_char_properties[c] & PG_ISLOWER));
450410
case PG_REGEX_BUILTIN:
451411
return pg_u_islower(c);
452-
case PG_REGEX_LOCALE_WIDE:
453-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
454-
return iswlower((wint_t) c);
455-
/* FALL THRU */
456-
case PG_REGEX_LOCALE_1BYTE:
457-
return (c <= (pg_wchar) UCHAR_MAX &&
458-
islower((unsigned char) c));
459412
case PG_REGEX_LOCALE_WIDE_L:
460413
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
461414
return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
@@ -483,13 +436,6 @@ pg_wc_isgraph(pg_wchar c)
483436
(pg_char_properties[c] & PG_ISGRAPH));
484437
case PG_REGEX_BUILTIN:
485438
return pg_u_isgraph(c);
486-
case PG_REGEX_LOCALE_WIDE:
487-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
488-
return iswgraph((wint_t) c);
489-
/* FALL THRU */
490-
case PG_REGEX_LOCALE_1BYTE:
491-
return (c <= (pg_wchar) UCHAR_MAX &&
492-
isgraph((unsigned char) c));
493439
case PG_REGEX_LOCALE_WIDE_L:
494440
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
495441
return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
@@ -517,13 +463,6 @@ pg_wc_isprint(pg_wchar c)
517463
(pg_char_properties[c] & PG_ISPRINT));
518464
case PG_REGEX_BUILTIN:
519465
return pg_u_isprint(c);
520-
case PG_REGEX_LOCALE_WIDE:
521-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
522-
return iswprint((wint_t) c);
523-
/* FALL THRU */
524-
case PG_REGEX_LOCALE_1BYTE:
525-
return (c <= (pg_wchar) UCHAR_MAX &&
526-
isprint((unsigned char) c));
527466
case PG_REGEX_LOCALE_WIDE_L:
528467
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
529468
return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
@@ -551,13 +490,6 @@ pg_wc_ispunct(pg_wchar c)
551490
(pg_char_properties[c] & PG_ISPUNCT));
552491
case PG_REGEX_BUILTIN:
553492
return pg_u_ispunct(c, true);
554-
case PG_REGEX_LOCALE_WIDE:
555-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
556-
return iswpunct((wint_t) c);
557-
/* FALL THRU */
558-
case PG_REGEX_LOCALE_1BYTE:
559-
return (c <= (pg_wchar) UCHAR_MAX &&
560-
ispunct((unsigned char) c));
561493
case PG_REGEX_LOCALE_WIDE_L:
562494
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
563495
return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
@@ -585,13 +517,6 @@ pg_wc_isspace(pg_wchar c)
585517
(pg_char_properties[c] & PG_ISSPACE));
586518
case PG_REGEX_BUILTIN:
587519
return pg_u_isspace(c);
588-
case PG_REGEX_LOCALE_WIDE:
589-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
590-
return iswspace((wint_t) c);
591-
/* FALL THRU */
592-
case PG_REGEX_LOCALE_1BYTE:
593-
return (c <= (pg_wchar) UCHAR_MAX &&
594-
isspace((unsigned char) c));
595520
case PG_REGEX_LOCALE_WIDE_L:
596521
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
597522
return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
@@ -620,20 +545,6 @@ pg_wc_toupper(pg_wchar c)
620545
return c;
621546
case PG_REGEX_BUILTIN:
622547
return unicode_uppercase_simple(c);
623-
case PG_REGEX_LOCALE_WIDE:
624-
/* force C behavior for ASCII characters, per comments above */
625-
if (c <= (pg_wchar) 127)
626-
return pg_ascii_toupper((unsigned char) c);
627-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
628-
return towupper((wint_t) c);
629-
/* FALL THRU */
630-
case PG_REGEX_LOCALE_1BYTE:
631-
/* force C behavior for ASCII characters, per comments above */
632-
if (c <= (pg_wchar) 127)
633-
return pg_ascii_toupper((unsigned char) c);
634-
if (c <= (pg_wchar) UCHAR_MAX)
635-
return toupper((unsigned char) c);
636-
return c;
637548
case PG_REGEX_LOCALE_WIDE_L:
638549
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
639550
return towupper_l((wint_t) c, pg_regex_locale->info.lt);
@@ -662,20 +573,6 @@ pg_wc_tolower(pg_wchar c)
662573
return c;
663574
case PG_REGEX_BUILTIN:
664575
return unicode_lowercase_simple(c);
665-
case PG_REGEX_LOCALE_WIDE:
666-
/* force C behavior for ASCII characters, per comments above */
667-
if (c <= (pg_wchar) 127)
668-
return pg_ascii_tolower((unsigned char) c);
669-
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
670-
return towlower((wint_t) c);
671-
/* FALL THRU */
672-
case PG_REGEX_LOCALE_1BYTE:
673-
/* force C behavior for ASCII characters, per comments above */
674-
if (c <= (pg_wchar) 127)
675-
return pg_ascii_tolower((unsigned char) c);
676-
if (c <= (pg_wchar) UCHAR_MAX)
677-
return tolower((unsigned char) c);
678-
return c;
679576
case PG_REGEX_LOCALE_WIDE_L:
680577
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
681578
return towlower_l((wint_t) c, pg_regex_locale->info.lt);
@@ -829,11 +726,9 @@ pg_ctype_get_cache(pg_wc_probefunc probefunc, int cclasscode)
829726
case PG_REGEX_BUILTIN:
830727
max_chr = (pg_wchar) MAX_SIMPLE_CHR;
831728
break;
832-
case PG_REGEX_LOCALE_WIDE:
833729
case PG_REGEX_LOCALE_WIDE_L:
834730
max_chr = (pg_wchar) MAX_SIMPLE_CHR;
835731
break;
836-
case PG_REGEX_LOCALE_1BYTE:
837732
case PG_REGEX_LOCALE_1BYTE_L:
838733
#if MAX_SIMPLE_CHR >= UCHAR_MAX
839734
max_chr = (pg_wchar) UCHAR_MAX;

0 commit comments

Comments
 (0)