From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 6A539385B50C; Mon, 20 Feb 2023 09:47:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A539385B50C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1676886437; bh=5wk4eAN/0zIh9zRVj+kavZqYqA0qq9aTfYum+RCafH0=; h=From:To:Subject:Date:From; b=UUH0SlKWwuzFjDja5Q7sfOPo+QjTqUClE5wqB5dutHE9Kufy/j62ZqM97WjpJM9kp 6qWZz7PWubHw4+eu+q8XaTZ9PlgfsWqh91YxpPa0LryUogVNyGx3vPsf4w48iAWlwO ZxnvvAutI0jymiqz8TS7jiuzSija6GKT2kiScbHE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: convert __collate_range_cmp to __wcollate_range_cmp X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: f0417a620182083fa787eea90e2e1d9884c8e573 X-Git-Newrev: 064e4bb8bb4236822c23ed63d419ba081f1e524a Message-Id: <20230220094717.6A539385B50C@sourceware.org> Date: Mon, 20 Feb 2023 09:47:17 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D064e4bb8bb4= 236822c23ed63d419ba081f1e524a commit 064e4bb8bb4236822c23ed63d419ba081f1e524a Author: Corinna Vinschen AuthorDate: Sun Feb 19 14:23:53 2023 +0100 Commit: Corinna Vinschen CommitDate: Sun Feb 19 14:40:29 2023 +0100 Cygwin: convert __collate_range_cmp to __wcollate_range_cmp =20 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D179721 =20 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...) =20 While at it, drop __collate_load_error and fix the checks for it in glob and fnmatch. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/glob.cc | 8 ++++++-- winsup/cygwin/globals.cc | 3 --- winsup/cygwin/libc/fnmatch.c | 12 ++++-------- winsup/cygwin/local_includes/collate.h | 2 +- winsup/cygwin/nlsfuncs.cc | 6 ++---- winsup/cygwin/regex/regcomp.c | 6 +++--- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index c882cd59d2e2..eb19e23de1ac 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 =3D 1; } else if ((*pat & M_MASK) =3D=3D M_RNG) { +#ifdef __CYGWIN__ + if ((!__get_current_collate_locale ()->lcid) ? +#else if (__collate_load_error ? +#endif CCHAR(c) <=3D CCHAR(k) && CCHAR(k) <=3D CCHAR(pat[1]) : - __collate_range_cmp(CCHAR(c), CCHAR(k)) <=3D 0 - && __collate_range_cmp(CCHAR(k), CCHAR(pat[1])) <=3D 0 + __wcollate_range_cmp(CCHAR(c), CCHAR(k)) <=3D 0 + && __wcollate_range_cmp(CCHAR(k), CCHAR(pat[1])) <=3D 0 ) ok =3D 1; pat +=3D 2; diff --git a/winsup/cygwin/globals.cc b/winsup/cygwin/globals.cc index aef4a687db60..c259ce18fc5d 100644 --- a/winsup/cygwin/globals.cc +++ b/winsup/cygwin/globals.cc @@ -96,9 +96,6 @@ char NO_COPY almost_null[1]; =20 extern "C" { =20 -/* We never have a collate load error. */ -const int __collate_load_error =3D 0; - /* Heavily-used const UNICODE_STRINGs are defined here once. The idea i= s a speed improvement by not having to initialize a UNICODE_STRING every = time we make a string comparison. The _RDATA trick allows defining the st= rings diff --git a/winsup/cygwin/libc/fnmatch.c b/winsup/cygwin/libc/fnmatch.c index 40c1f2d59859..dfbe3863fbfa 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 flag= s, char **newp, c2 =3D towlower(c2); =20 #ifdef __CYGWIN__ - if (__collate_load_error ? - c <=3D test && test <=3D c2 : - __collate_range_cmp(c, test) <=3D 0 - && __collate_range_cmp(test, c2) <=3D 0 - ) + if ((!__get_current_collate_locale ()->lcid) ? #else if (table->__collate_load_error ? +#endif c <=3D test && test <=3D c2 : - __collate_range_cmp(table, c, test) <=3D 0 - && __collate_range_cmp(table, test, c2) <=3D 0 + __wcollate_range_cmp(c, test) <=3D 0 + && __wcollate_range_cmp(test, c2) <=3D 0 ) -#endif ok =3D 1; } else if (c =3D=3D test) ok =3D 1; diff --git a/winsup/cygwin/local_includes/collate.h b/winsup/cygwin/local_i= ncludes/collate.h index c3454575dd92..d9e84f32ebba 100644 --- a/winsup/cygwin/local_includes/collate.h +++ b/winsup/cygwin/local_includes/collate.h @@ -13,7 +13,7 @@ extern "C" { =20 extern const int __collate_load_error; =20 -extern int __collate_range_cmp (int c1, int c2); +extern int __wcollate_range_cmp (wint_t, wint_t); =20 int is_unicode_equiv (wint_t, wint_t); =20 diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc index d80567737d7b..4d17fb4e39cd 100644 --- a/winsup/cygwin/nlsfuncs.cc +++ b/winsup/cygwin/nlsfuncs.cc @@ -1172,11 +1172,9 @@ strcoll (const char *__restrict s1, const char *__re= strict s2) return strcoll_l (s1, s2, __get_current_locale ()); } =20 -/* 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] =3D { (wchar_t) c1, L'\0', L'\0' }; wchar_t s2[3] =3D { (wchar_t) c2, L'\0', L'\0' }; diff --git a/winsup/cygwin/regex/regcomp.c b/winsup/cygwin/regex/regcomp.c index aef104c1ea45..5acfd4e52e61 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 <=3D (uch)finish, REG_ERANGE); CHaddrange(p, cs, start, finish); } else { - (void)REQUIRE(__collate_range_cmp(start, finish) <=3D 0, REG_ERANGE); + (void)REQUIRE(__wcollate_range_cmp(start, finish) <=3D 0, REG_ERANGE); for (i =3D 0; i <=3D UCHAR_MAX; i++) { - if ( __collate_range_cmp(start, i) <=3D 0 - && __collate_range_cmp(i, finish) <=3D 0 + if ( __wcollate_range_cmp(start, i) <=3D 0 + && __wcollate_range_cmp(i, finish) <=3D 0 ) CHadd(p, cs, i); }