Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Jan 2018 02:58:33 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r328241 - head/lib/libc/regex
Message-ID:  <201801220258.w0M2wXdN087208@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Mon Jan 22 02:58:33 2018
New Revision: 328241
URL: https://svnweb.freebsd.org/changeset/base/328241

Log:
  Add missing patch from r328240
  
  regcomp uses some libc internal collation bits that are not available in the
  libregex context. It's easy enough to bring in the needed parts that can
  work in a libregex world, so do so.
  
  Pointy hat to:	me

Modified:
  head/lib/libc/regex/regcomp.c

Modified: head/lib/libc/regex/regcomp.c
==============================================================================
--- head/lib/libc/regex/regcomp.c	Mon Jan 22 02:44:41 2018	(r328240)
+++ head/lib/libc/regex/regcomp.c	Mon Jan 22 02:58:33 2018	(r328241)
@@ -57,7 +57,9 @@ __FBSDID("$FreeBSD$");
 #include <wchar.h>
 #include <wctype.h>
 
+#ifndef LIBREGEX
 #include "collate.h"
+#endif
 
 #include "utils.h"
 #include "regex2.h"
@@ -124,6 +126,7 @@ static void p_re(struct parse *p, int end1, int end2);
 static bool p_simp_re(struct parse *p, struct branchc *bc);
 static int p_count(struct parse *p);
 static void p_bracket(struct parse *p);
+static int p_range_cmp(wchar_t c1, wchar_t c2);
 static void p_b_term(struct parse *p, cset *cs);
 static void p_b_cclass(struct parse *p, cset *cs);
 static void p_b_eclass(struct parse *p, cset *cs);
@@ -904,6 +907,23 @@ p_bracket(struct parse *p)
 		EMIT(OANYOF, (int)(cs - p->g->sets));
 }
 
+static int
+p_range_cmp(wchar_t c1, wchar_t c2)
+{
+#ifndef LIBREGEX
+	return __wcollate_range_cmp(c1, c2);
+#else
+	/* Copied from libc/collate __wcollate_range_cmp */
+	wchar_t s1[2], s2[2];
+
+	s1[0] = c1;
+	s1[1] = L'\0';
+	s2[0] = c2;
+	s2[1] = L'\0';
+	return (wcscoll(s1, s2));
+#endif
+}
+
 /*
  - p_b_term - parse one term of a bracketed character list
  == static void p_b_term(struct parse *p, cset *cs);
@@ -914,9 +934,10 @@ p_b_term(struct parse *p, cset *cs)
 	char c;
 	wint_t start, finish;
 	wint_t i;
+#ifndef LIBREGEX
 	struct xlocale_collate *table =
 		(struct xlocale_collate*)__get_locale()->components[XLC_COLLATE];
-
+#endif
 	/* classify what we've got */
 	switch ((MORE()) ? PEEK() : '\0') {
 	case '[':
@@ -963,15 +984,18 @@ p_b_term(struct parse *p, cset *cs)
 		if (start == finish)
 			CHadd(p, cs, start);
 		else {
+#ifndef LIBREGEX
 			if (table->__collate_load_error || MB_CUR_MAX > 1) {
+#else
+			if (MB_CUR_MAX > 1) {
+#endif
 				(void)REQUIRE(start <= finish, REG_ERANGE);
 				CHaddrange(p, cs, start, finish);
 			} else {
-				(void)REQUIRE(__wcollate_range_cmp(start, finish) <= 0, REG_ERANGE);
+				(void)REQUIRE(p_range_cmp(start, finish) <= 0, REG_ERANGE);
 				for (i = 0; i <= UCHAR_MAX; i++) {
-					if (   __wcollate_range_cmp(start, i) <= 0
-					    && __wcollate_range_cmp(i, finish) <= 0
-					   )
+					if (p_range_cmp(start, i) <= 0 &&
+					    p_range_cmp(i, finish) <= 0 )
 						CHadd(p, cs, i);
 				}
 			}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801220258.w0M2wXdN087208>