Skip to content

Commit 8d9a9f0

Browse files
committed
All supported systems have locale_t.
locale_t is defined by POSIX.1-2008 and SUSv4, and available on all targeted systems. For Windows, win32_port.h redirects to a partial implementation called _locale_t. We can now remove a lot of compile-time tests for HAVE_LOCALE_T, and associated comments and dead code branches that were needed for older computers. Since configure + MinGW builds didn't detect locale_t but now we assume that all systems have it, further inconsistencies among the 3 Windows build systems were revealed. With this commit, we no longer define HAVE_WCSTOMBS_L and HAVE_MBSTOWCS_L on any Windows build system, but we have logic to deal with that so that replacements are available where appropriate. Reviewed-by: Noah Misch <noah@leadboat.com> Reviewed-by: Tristan Partin <tristan@neon.tech> Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/CA%2BhUKGLg7_T2GKwZFAkEf0V7vbnur-NfCjZPKZb%3DZfAXSV1ORw%40mail.gmail.com
1 parent e9f15bc commit 8d9a9f0

File tree

12 files changed

+46
-169
lines changed

12 files changed

+46
-169
lines changed

config/c-library.m4

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ AC_DEFUN([PGAC_STRUCT_SOCKADDR_SA_LEN],
8686
# PGAC_TYPE_LOCALE_T
8787
# ------------------
8888
# Check for the locale_t type and find the right header file. macOS
89-
# needs xlocale.h; standard is locale.h, but glibc also has an
90-
# xlocale.h file that we should not use.
91-
#
89+
# needs xlocale.h; standard is locale.h, but glibc <= 2.25 also had an
90+
# xlocale.h file that we should not use, so we check the standard
91+
# header first.
9292
AC_DEFUN([PGAC_TYPE_LOCALE_T],
9393
[AC_CACHE_CHECK([for locale_t], pgac_cv_type_locale_t,
9494
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
@@ -102,10 +102,6 @@ locale_t x;],
102102
[])],
103103
[pgac_cv_type_locale_t='yes (in xlocale.h)'],
104104
[pgac_cv_type_locale_t=no])])])
105-
if test "$pgac_cv_type_locale_t" != no; then
106-
AC_DEFINE(HAVE_LOCALE_T, 1,
107-
[Define to 1 if the system has the type `locale_t'.])
108-
fi
109105
if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
110106
AC_DEFINE(LOCALE_T_IN_XLOCALE, 1,
111107
[Define to 1 if `locale_t' requires <xlocale.h>.])

configure

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15120,11 +15120,6 @@ rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
1512015120
fi
1512115121
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_type_locale_t" >&5
1512215122
$as_echo "$pgac_cv_type_locale_t" >&6; }
15123-
if test "$pgac_cv_type_locale_t" != no; then
15124-
15125-
$as_echo "#define HAVE_LOCALE_T 1" >>confdefs.h
15126-
15127-
fi
1512815123
if test "$pgac_cv_type_locale_t" = 'yes (in xlocale.h)'; then
1512915124

1513015125
$as_echo "#define LOCALE_T_IN_XLOCALE 1" >>confdefs.h

meson.build

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,17 +2283,13 @@ else
22832283
cdata.set('STRERROR_R_INT', false)
22842284
endif
22852285

2286-
# Check for the locale_t type and find the right header file. macOS
2287-
# needs xlocale.h; standard is locale.h, but glibc also has an
2288-
# xlocale.h file that we should not use. MSVC has a replacement
2289-
# defined in src/include/port/win32_port.h.
2290-
if cc.has_type('locale_t', prefix: '#include <locale.h>')
2291-
cdata.set('HAVE_LOCALE_T', 1)
2292-
elif cc.has_type('locale_t', prefix: '#include <xlocale.h>')
2293-
cdata.set('HAVE_LOCALE_T', 1)
2286+
# Find the right header file for the locale_t type. macOS needs xlocale.h;
2287+
# standard is locale.h, but glibc <= 2.25 also had an xlocale.h file that
2288+
# we should not use so we check the standard header first. MSVC has a
2289+
# replacement defined in src/include/port/win32_port.h.
2290+
if not cc.has_type('locale_t', prefix: '#include <locale.h>') and \
2291+
cc.has_type('locale_t', prefix: '#include <xlocale.h>')
22942292
cdata.set('LOCALE_T_IN_XLOCALE', 1)
2295-
elif cc.get_id() == 'msvc'
2296-
cdata.set('HAVE_LOCALE_T', 1)
22972293
endif
22982294

22992295
# Check if the C compiler understands typeof or a variant. Define
@@ -2489,13 +2485,6 @@ if cc.has_function('syslog', args: test_c_args) and \
24892485
endif
24902486

24912487

2492-
# MSVC has replacements defined in src/include/port/win32_port.h.
2493-
if cc.get_id() == 'msvc'
2494-
cdata.set('HAVE_WCSTOMBS_L', 1)
2495-
cdata.set('HAVE_MBSTOWCS_L', 1)
2496-
endif
2497-
2498-
24992488
# if prerequisites for unnamed posix semas aren't fulfilled, fall back to sysv
25002489
# semaphores
25012490
if sema_kind == 'unnamed_posix' and \

src/backend/commands/collationcmds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ pg_collation_actual_version(PG_FUNCTION_ARGS)
534534

535535

536536
/* will we use "locale -a" in pg_import_system_collations? */
537-
#if defined(HAVE_LOCALE_T) && !defined(WIN32)
537+
#if !defined(WIN32)
538538
#define READ_LOCALE_A_OUTPUT
539539
#endif
540540

src/backend/regex/regc_pg_locale.c

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@
4444
* the platform's wchar_t representation matches what we do in pg_wchar
4545
* conversions.
4646
*
47-
* 3. Other collations are only supported on platforms that HAVE_LOCALE_T.
48-
* Here, we use the locale_t-extended forms of the <wctype.h> and <ctype.h>
47+
* 3. Here, we use the locale_t-extended forms of the <wctype.h> and <ctype.h>
4948
* functions, under exactly the same cases as #2.
5049
*
5150
* There is one notable difference between cases 2 and 3: in the "default"
@@ -252,11 +251,6 @@ pg_set_regex_collation(Oid collation)
252251
}
253252
else
254253
{
255-
/*
256-
* NB: pg_newlocale_from_collation will fail if not HAVE_LOCALE_T; the
257-
* case of pg_regex_locale != 0 but not HAVE_LOCALE_T does not have to
258-
* be considered below.
259-
*/
260254
pg_regex_locale = pg_newlocale_from_collation(collation);
261255

262256
if (!pg_locale_deterministic(pg_regex_locale))
@@ -304,16 +298,12 @@ pg_wc_isdigit(pg_wchar c)
304298
return (c <= (pg_wchar) UCHAR_MAX &&
305299
isdigit((unsigned char) c));
306300
case PG_REGEX_LOCALE_WIDE_L:
307-
#ifdef HAVE_LOCALE_T
308301
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
309302
return iswdigit_l((wint_t) c, pg_regex_locale->info.lt);
310-
#endif
311303
/* FALL THRU */
312304
case PG_REGEX_LOCALE_1BYTE_L:
313-
#ifdef HAVE_LOCALE_T
314305
return (c <= (pg_wchar) UCHAR_MAX &&
315306
isdigit_l((unsigned char) c, pg_regex_locale->info.lt));
316-
#endif
317307
break;
318308
case PG_REGEX_LOCALE_ICU:
319309
#ifdef USE_ICU
@@ -340,16 +330,12 @@ pg_wc_isalpha(pg_wchar c)
340330
return (c <= (pg_wchar) UCHAR_MAX &&
341331
isalpha((unsigned char) c));
342332
case PG_REGEX_LOCALE_WIDE_L:
343-
#ifdef HAVE_LOCALE_T
344333
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
345334
return iswalpha_l((wint_t) c, pg_regex_locale->info.lt);
346-
#endif
347335
/* FALL THRU */
348336
case PG_REGEX_LOCALE_1BYTE_L:
349-
#ifdef HAVE_LOCALE_T
350337
return (c <= (pg_wchar) UCHAR_MAX &&
351338
isalpha_l((unsigned char) c, pg_regex_locale->info.lt));
352-
#endif
353339
break;
354340
case PG_REGEX_LOCALE_ICU:
355341
#ifdef USE_ICU
@@ -376,16 +362,12 @@ pg_wc_isalnum(pg_wchar c)
376362
return (c <= (pg_wchar) UCHAR_MAX &&
377363
isalnum((unsigned char) c));
378364
case PG_REGEX_LOCALE_WIDE_L:
379-
#ifdef HAVE_LOCALE_T
380365
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
381366
return iswalnum_l((wint_t) c, pg_regex_locale->info.lt);
382-
#endif
383367
/* FALL THRU */
384368
case PG_REGEX_LOCALE_1BYTE_L:
385-
#ifdef HAVE_LOCALE_T
386369
return (c <= (pg_wchar) UCHAR_MAX &&
387370
isalnum_l((unsigned char) c, pg_regex_locale->info.lt));
388-
#endif
389371
break;
390372
case PG_REGEX_LOCALE_ICU:
391373
#ifdef USE_ICU
@@ -421,16 +403,12 @@ pg_wc_isupper(pg_wchar c)
421403
return (c <= (pg_wchar) UCHAR_MAX &&
422404
isupper((unsigned char) c));
423405
case PG_REGEX_LOCALE_WIDE_L:
424-
#ifdef HAVE_LOCALE_T
425406
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
426407
return iswupper_l((wint_t) c, pg_regex_locale->info.lt);
427-
#endif
428408
/* FALL THRU */
429409
case PG_REGEX_LOCALE_1BYTE_L:
430-
#ifdef HAVE_LOCALE_T
431410
return (c <= (pg_wchar) UCHAR_MAX &&
432411
isupper_l((unsigned char) c, pg_regex_locale->info.lt));
433-
#endif
434412
break;
435413
case PG_REGEX_LOCALE_ICU:
436414
#ifdef USE_ICU
@@ -457,16 +435,12 @@ pg_wc_islower(pg_wchar c)
457435
return (c <= (pg_wchar) UCHAR_MAX &&
458436
islower((unsigned char) c));
459437
case PG_REGEX_LOCALE_WIDE_L:
460-
#ifdef HAVE_LOCALE_T
461438
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
462439
return iswlower_l((wint_t) c, pg_regex_locale->info.lt);
463-
#endif
464440
/* FALL THRU */
465441
case PG_REGEX_LOCALE_1BYTE_L:
466-
#ifdef HAVE_LOCALE_T
467442
return (c <= (pg_wchar) UCHAR_MAX &&
468443
islower_l((unsigned char) c, pg_regex_locale->info.lt));
469-
#endif
470444
break;
471445
case PG_REGEX_LOCALE_ICU:
472446
#ifdef USE_ICU
@@ -493,16 +467,12 @@ pg_wc_isgraph(pg_wchar c)
493467
return (c <= (pg_wchar) UCHAR_MAX &&
494468
isgraph((unsigned char) c));
495469
case PG_REGEX_LOCALE_WIDE_L:
496-
#ifdef HAVE_LOCALE_T
497470
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
498471
return iswgraph_l((wint_t) c, pg_regex_locale->info.lt);
499-
#endif
500472
/* FALL THRU */
501473
case PG_REGEX_LOCALE_1BYTE_L:
502-
#ifdef HAVE_LOCALE_T
503474
return (c <= (pg_wchar) UCHAR_MAX &&
504475
isgraph_l((unsigned char) c, pg_regex_locale->info.lt));
505-
#endif
506476
break;
507477
case PG_REGEX_LOCALE_ICU:
508478
#ifdef USE_ICU
@@ -529,16 +499,12 @@ pg_wc_isprint(pg_wchar c)
529499
return (c <= (pg_wchar) UCHAR_MAX &&
530500
isprint((unsigned char) c));
531501
case PG_REGEX_LOCALE_WIDE_L:
532-
#ifdef HAVE_LOCALE_T
533502
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
534503
return iswprint_l((wint_t) c, pg_regex_locale->info.lt);
535-
#endif
536504
/* FALL THRU */
537505
case PG_REGEX_LOCALE_1BYTE_L:
538-
#ifdef HAVE_LOCALE_T
539506
return (c <= (pg_wchar) UCHAR_MAX &&
540507
isprint_l((unsigned char) c, pg_regex_locale->info.lt));
541-
#endif
542508
break;
543509
case PG_REGEX_LOCALE_ICU:
544510
#ifdef USE_ICU
@@ -565,16 +531,12 @@ pg_wc_ispunct(pg_wchar c)
565531
return (c <= (pg_wchar) UCHAR_MAX &&
566532
ispunct((unsigned char) c));
567533
case PG_REGEX_LOCALE_WIDE_L:
568-
#ifdef HAVE_LOCALE_T
569534
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
570535
return iswpunct_l((wint_t) c, pg_regex_locale->info.lt);
571-
#endif
572536
/* FALL THRU */
573537
case PG_REGEX_LOCALE_1BYTE_L:
574-
#ifdef HAVE_LOCALE_T
575538
return (c <= (pg_wchar) UCHAR_MAX &&
576539
ispunct_l((unsigned char) c, pg_regex_locale->info.lt));
577-
#endif
578540
break;
579541
case PG_REGEX_LOCALE_ICU:
580542
#ifdef USE_ICU
@@ -601,16 +563,12 @@ pg_wc_isspace(pg_wchar c)
601563
return (c <= (pg_wchar) UCHAR_MAX &&
602564
isspace((unsigned char) c));
603565
case PG_REGEX_LOCALE_WIDE_L:
604-
#ifdef HAVE_LOCALE_T
605566
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
606567
return iswspace_l((wint_t) c, pg_regex_locale->info.lt);
607-
#endif
608568
/* FALL THRU */
609569
case PG_REGEX_LOCALE_1BYTE_L:
610-
#ifdef HAVE_LOCALE_T
611570
return (c <= (pg_wchar) UCHAR_MAX &&
612571
isspace_l((unsigned char) c, pg_regex_locale->info.lt));
613-
#endif
614572
break;
615573
case PG_REGEX_LOCALE_ICU:
616574
#ifdef USE_ICU
@@ -645,16 +603,12 @@ pg_wc_toupper(pg_wchar c)
645603
return toupper((unsigned char) c);
646604
return c;
647605
case PG_REGEX_LOCALE_WIDE_L:
648-
#ifdef HAVE_LOCALE_T
649606
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
650607
return towupper_l((wint_t) c, pg_regex_locale->info.lt);
651-
#endif
652608
/* FALL THRU */
653609
case PG_REGEX_LOCALE_1BYTE_L:
654-
#ifdef HAVE_LOCALE_T
655610
if (c <= (pg_wchar) UCHAR_MAX)
656611
return toupper_l((unsigned char) c, pg_regex_locale->info.lt);
657-
#endif
658612
return c;
659613
case PG_REGEX_LOCALE_ICU:
660614
#ifdef USE_ICU
@@ -689,16 +643,12 @@ pg_wc_tolower(pg_wchar c)
689643
return tolower((unsigned char) c);
690644
return c;
691645
case PG_REGEX_LOCALE_WIDE_L:
692-
#ifdef HAVE_LOCALE_T
693646
if (sizeof(wchar_t) >= 4 || c <= (pg_wchar) 0xFFFF)
694647
return towlower_l((wint_t) c, pg_regex_locale->info.lt);
695-
#endif
696648
/* FALL THRU */
697649
case PG_REGEX_LOCALE_1BYTE_L:
698-
#ifdef HAVE_LOCALE_T
699650
if (c <= (pg_wchar) UCHAR_MAX)
700651
return tolower_l((unsigned char) c, pg_regex_locale->info.lt);
701-
#endif
702652
return c;
703653
case PG_REGEX_LOCALE_ICU:
704654
#ifdef USE_ICU

src/backend/utils/adt/formatting.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,12 +1613,6 @@ u_strToTitle_default_BI(UChar *dest, int32_t destCapacity,
16131613
* in multibyte character sets. Note that in either case we are effectively
16141614
* assuming that the database character encoding matches the encoding implied
16151615
* by LC_CTYPE.
1616-
*
1617-
* If the system provides locale_t and associated functions (which are
1618-
* standardized by Open Group's XBD), we can support collations that are
1619-
* neither default nor C. The code is written to handle both combinations
1620-
* of have-wide-characters and have-locale_t, though it's rather unlikely
1621-
* a platform would have the latter without the former.
16221616
*/
16231617

16241618
/*
@@ -1696,11 +1690,9 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
16961690

16971691
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
16981692
{
1699-
#ifdef HAVE_LOCALE_T
17001693
if (mylocale)
17011694
workspace[curr_char] = towlower_l(workspace[curr_char], mylocale->info.lt);
17021695
else
1703-
#endif
17041696
workspace[curr_char] = towlower(workspace[curr_char]);
17051697
}
17061698

@@ -1729,11 +1721,9 @@ str_tolower(const char *buff, size_t nbytes, Oid collid)
17291721
*/
17301722
for (p = result; *p; p++)
17311723
{
1732-
#ifdef HAVE_LOCALE_T
17331724
if (mylocale)
17341725
*p = tolower_l((unsigned char) *p, mylocale->info.lt);
17351726
else
1736-
#endif
17371727
*p = pg_tolower((unsigned char) *p);
17381728
}
17391729
}
@@ -1818,11 +1808,9 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
18181808

18191809
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
18201810
{
1821-
#ifdef HAVE_LOCALE_T
18221811
if (mylocale)
18231812
workspace[curr_char] = towupper_l(workspace[curr_char], mylocale->info.lt);
18241813
else
1825-
#endif
18261814
workspace[curr_char] = towupper(workspace[curr_char]);
18271815
}
18281816

@@ -1851,11 +1839,9 @@ str_toupper(const char *buff, size_t nbytes, Oid collid)
18511839
*/
18521840
for (p = result; *p; p++)
18531841
{
1854-
#ifdef HAVE_LOCALE_T
18551842
if (mylocale)
18561843
*p = toupper_l((unsigned char) *p, mylocale->info.lt);
18571844
else
1858-
#endif
18591845
*p = pg_toupper((unsigned char) *p);
18601846
}
18611847
}
@@ -1941,7 +1927,6 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
19411927

19421928
for (curr_char = 0; workspace[curr_char] != 0; curr_char++)
19431929
{
1944-
#ifdef HAVE_LOCALE_T
19451930
if (mylocale)
19461931
{
19471932
if (wasalnum)
@@ -1951,7 +1936,6 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
19511936
wasalnum = iswalnum_l(workspace[curr_char], mylocale->info.lt);
19521937
}
19531938
else
1954-
#endif
19551939
{
19561940
if (wasalnum)
19571941
workspace[curr_char] = towlower(workspace[curr_char]);
@@ -1986,7 +1970,6 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
19861970
*/
19871971
for (p = result; *p; p++)
19881972
{
1989-
#ifdef HAVE_LOCALE_T
19901973
if (mylocale)
19911974
{
19921975
if (wasalnum)
@@ -1996,7 +1979,6 @@ str_initcap(const char *buff, size_t nbytes, Oid collid)
19961979
wasalnum = isalnum_l((unsigned char) *p, mylocale->info.lt);
19971980
}
19981981
else
1999-
#endif
20001982
{
20011983
if (wasalnum)
20021984
*p = pg_tolower((unsigned char) *p);

src/backend/utils/adt/like.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ SB_lower_char(unsigned char c, pg_locale_t locale, bool locale_is_c)
9595
{
9696
if (locale_is_c)
9797
return pg_ascii_tolower(c);
98-
#ifdef HAVE_LOCALE_T
9998
else if (locale)
10099
return tolower_l(c, locale->info.lt);
101-
#endif
102100
else
103101
return pg_tolower(c);
104102
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy