public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: convert __collate_range_cmp to __wcollate_range_cmp
Date: Mon, 20 Feb 2023 09:47:17 +0000 (GMT)	[thread overview]
Message-ID: <20230220094717.6A539385B50C@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=064e4bb8bb4236822c23ed63d419ba081f1e524a

commit 064e4bb8bb4236822c23ed63d419ba081f1e524a
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Sun Feb 19 14:23:53 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Sun Feb 19 14:40:29 2023 +0100

    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 <corinna@vinschen.de>

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 = 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 aef4a687db60..c259ce18fc5d 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 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 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 ?
+#endif
 			    c <= test && test <= c2 :
-			       __collate_range_cmp(table, c, test) <= 0
-			    && __collate_range_cmp(table, test, c2) <= 0
+			       __wcollate_range_cmp(c, test) <= 0
+			    && __wcollate_range_cmp(test, c2) <= 0
 			   )
-#endif
 				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 c3454575dd92..d9e84f32ebba 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 d80567737d7b..4d17fb4e39cd 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 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 <= (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);
 				}

                 reply	other threads:[~2023-02-20  9:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230220094717.6A539385B50C@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).