From 064e4bb8bb4236822c23ed63d419ba081f1e524a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sun, 19 Feb 2023 14:23:53 +0100 Subject: [PATCH] Cygwin: convert __collate_range_cmp to __wcollate_range_cmp https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=179721 After FreeBSD eventually picked up the bugreport from within only 5 years, rename __collate_range_cmp to __wcollate_range_cmp as suggested all along, and make it type safe (wint_t instead of wchar_t for hopefully obvious reasons...) While at it, drop __collate_load_error and fix the checks for it in glob and fnmatch. Signed-off-by: Corinna Vinschen --- winsup/cygwin/glob.cc | 8 ++++++-- winsup/cygwin/globals.cc | 3 --- winsup/cygwin/libc/fnmatch.c | 14 +++++--------- winsup/cygwin/local_includes/collate.h | 2 +- winsup/cygwin/nlsfuncs.cc | 6 ++---- winsup/cygwin/regex/regcomp.c | 6 +++--- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index c882cd59d..eb19e23de 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -879,10 +879,14 @@ match(Char *name, Char *pat, Char *patend) if (is_unicode_equiv (k, *pat++)) ok = 1; } else if ((*pat & M_MASK) == M_RNG) { +#ifdef __CYGWIN__ + if ((!__get_current_collate_locale ()->lcid) ? +#else if (__collate_load_error ? +#endif CCHAR(c) <= CCHAR(k) && CCHAR(k) <= CCHAR(pat[1]) : - __collate_range_cmp(CCHAR(c), CCHAR(k)) <= 0 - && __collate_range_cmp(CCHAR(k), CCHAR(pat[1])) <= 0 + __wcollate_range_cmp(CCHAR(c), CCHAR(k)) <= 0 + && __wcollate_range_cmp(CCHAR(k), CCHAR(pat[1])) <= 0 ) ok = 1; pat += 2; diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index aef4a687d..c259ce18f 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -96,9 +96,6 @@ char NO_COPY almost_null[1]; extern "C" { -/* We never have a collate load error. */ -const int __collate_load_error = 0; - /* Heavily-used const UNICODE_STRINGs are defined here once. The idea is a speed improvement by not having to initialize a UNICODE_STRING every time we make a string comparison. The _RDATA trick allows defining the strings diff --git a/winsup/cygwin/libc/fnmatch.c b/winsup/cygwin/libc/fnmatch.c index 40c1f2d59..dfbe3863f 100644 --- a/winsup/cygwin/libc/fnmatch.c +++ b/winsup/cygwin/libc/fnmatch.c @@ -330,18 +330,14 @@ rangematch(const char *pattern, wint_t test, int flags, char **newp, c2 = towlower(c2); #ifdef __CYGWIN__ - if (__collate_load_error ? - c <= test && test <= c2 : - __collate_range_cmp(c, test) <= 0 - && __collate_range_cmp(test, c2) <= 0 - ) + if ((!__get_current_collate_locale ()->lcid) ? #else if (table->__collate_load_error ? - c <= test && test <= c2 : - __collate_range_cmp(table, c, test) <= 0 - && __collate_range_cmp(table, test, c2) <= 0 - ) #endif + c <= test && test <= c2 : + __wcollate_range_cmp(c, test) <= 0 + && __wcollate_range_cmp(test, c2) <= 0 + ) ok = 1; } else if (c == test) ok = 1; diff --git a/winsup/cygwin/local_includes/collate.h b/winsup/cygwin/local_includes/collate.h index c3454575d..d9e84f32e 100644 --- a/winsup/cygwin/local_includes/collate.h +++ b/winsup/cygwin/local_includes/collate.h @@ -13,7 +13,7 @@ extern "C" { extern const int __collate_load_error; -extern int __collate_range_cmp (int c1, int c2); +extern int __wcollate_range_cmp (wint_t, wint_t); int is_unicode_equiv (wint_t, wint_t); diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc index d80567737..4d17fb4e3 100644 --- a/winsup/cygwin/nlsfuncs.cc +++ b/winsup/cygwin/nlsfuncs.cc @@ -1172,11 +1172,9 @@ strcoll (const char *__restrict s1, const char *__restrict s2) return strcoll_l (s1, s2, __get_current_locale ()); } -/* BSD. Used from glob.cc, fnmatch.c and regcomp.c. Make sure caller is - using wide chars. Unfortunately the definition of this functions hides - the required input type. */ +/* BSD. Used from glob.cc, fnmatch.c and regcomp.c. */ extern "C" int -__collate_range_cmp (int c1, int c2) +__wcollate_range_cmp (wint_t c1, wint_t c2) { wchar_t s1[3] = { (wchar_t) c1, L'\0', L'\0' }; wchar_t s2[3] = { (wchar_t) c2, L'\0', L'\0' }; diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c index aef104c1e..5acfd4e52 100644 --- a/winsup/cygwin/regex/regcomp.c +++ b/winsup/cygwin/regex/regcomp.c @@ -834,10 +834,10 @@ p_b_term(struct parse *p, cset *cs) (void)REQUIRE((uch)start <= (uch)finish, REG_ERANGE); CHaddrange(p, cs, start, finish); } else { - (void)REQUIRE(__collate_range_cmp(start, finish) <= 0, REG_ERANGE); + (void)REQUIRE(__wcollate_range_cmp(start, finish) <= 0, REG_ERANGE); for (i = 0; i <= UCHAR_MAX; i++) { - if ( __collate_range_cmp(start, i) <= 0 - && __collate_range_cmp(i, finish) <= 0 + if ( __wcollate_range_cmp(start, i) <= 0 + && __wcollate_range_cmp(i, finish) <= 0 ) CHadd(p, cs, i); }