summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-11-21 16:54:31 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-11-21 16:54:32 +0900
commit73dd6e05c585d615d229f1a3af1d1a087dd50421 (patch)
tree0797bf70f3be6881d5df436fcf8a4750fc1bf308
parent16c400129adc39d7f3f789a2a0fe4fd06c5b3f82 (diff)
downloadre2-73dd6e05c585d615d229f1a3af1d1a087dd50421.tar.gz
re2-73dd6e05c585d615d229f1a3af1d1a087dd50421.tar.bz2
re2-73dd6e05c585d615d229f1a3af1d1a087dd50421.zip
Imported Upstream version 20150601upstream/20150601
Change-Id: Idfa2fac0fcc3d292a47b4eda4d8b2cf0c527eb56 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
-rw-r--r--Makefile5
-rw-r--r--README1
-rw-r--r--re2.pc10
-rw-r--r--re2/compile.cc3
-rw-r--r--re2/parse.cc3
-rw-r--r--re2/re2.cc2
-rw-r--r--re2/re2.h12
-rw-r--r--re2/testing/compile_test.cc4
-rw-r--r--re2/testing/re2_test.cc11
-rw-r--r--util/util.h21
10 files changed, 55 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index f4d6b52..fd93441 100644
--- a/Makefile
+++ b/Makefile
@@ -245,18 +245,21 @@ shared-bigtest: $(STESTS) $(SBIGTESTS)
benchmark: obj/test/regexp_benchmark
install: obj/libre2.a obj/so/libre2.so
- mkdir -p $(DESTDIR)$(includedir)/re2 $(DESTDIR)$(libdir)
+ mkdir -p $(DESTDIR)$(includedir)/re2 $(DESTDIR)$(libdir)/pkgconfig
$(INSTALL_DATA) $(INSTALL_HFILES) $(DESTDIR)$(includedir)/re2
$(INSTALL) obj/libre2.a $(DESTDIR)$(libdir)/libre2.a
$(INSTALL) obj/so/libre2.so $(DESTDIR)$(libdir)/libre2.so.$(SONAME).0.0
ln -sf libre2.so.$(SONAME).0.0 $(DESTDIR)$(libdir)/libre2.so.$(SONAME)
ln -sf libre2.so.$(SONAME).0.0 $(DESTDIR)$(libdir)/libre2.so
+ sed -e "s#@prefix@#${prefix}#" re2.pc >$(DESTDIR)$(libdir)/pkgconfig/re2.pc
testinstall:
@mkdir -p obj
cp testinstall.cc obj
+ifneq ($(shell uname),Darwin)
(cd obj && $(CXX) -I$(DESTDIR)$(includedir) -L$(DESTDIR)$(libdir) testinstall.cc -lre2 -pthread -static -o testinstall)
obj/testinstall
+endif
(cd obj && $(CXX) -I$(DESTDIR)$(includedir) -L$(DESTDIR)$(libdir) testinstall.cc -lre2 -pthread -o testinstall)
LD_LIBRARY_PATH=$(DESTDIR)$(libdir) obj/testinstall
diff --git a/README b/README
index 3143fbe..3cba956 100644
--- a/README
+++ b/README
@@ -25,5 +25,6 @@ under the BSD-style license found in the LICENSE file.
RE2's native language is C++.
An Erlang wrapper is at https://github.com/tuncer/re2/.
An Inferno wrapper is at https://github.com/powerman/inferno-re2/.
+A Perl wrapper is at https://github.com/dgl/re-engine-RE2/ and on CPAN.
A Python wrapper is at https://github.com/facebook/pyre2/.
A Ruby wrapper is at https://github.com/axic/rre2/.
diff --git a/re2.pc b/re2.pc
new file mode 100644
index 0000000..9e90cda
--- /dev/null
+++ b/re2.pc
@@ -0,0 +1,10 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+includedir=${prefix}/include
+libdir=${exec_prefix}/lib
+
+Name: re2
+Description: RE2 is a fast, safe, thread-friendly regular expression engine.
+Version: 0.0.0
+Cflags: -I${includedir}
+Libs: -L${libdir} -lre2 -pthread
diff --git a/re2/compile.cc b/re2/compile.cc
index 4d84ef3..6478def 100644
--- a/re2/compile.cc
+++ b/re2/compile.cc
@@ -815,7 +815,8 @@ Frag Compiler::PostVisit(Regexp* re, Frag, Frag, Frag* child_frags,
// If this range contains all of A-Za-z or none of it,
// the fold flag is unnecessary; don't bother.
bool fold = foldascii;
- if ((i->lo <= 'A' && 'z' <= i->hi) || i->hi < 'A' || 'z' < i->lo)
+ if ((i->lo <= 'A' && 'z' <= i->hi) || i->hi < 'A' || 'z' < i->lo ||
+ ('Z' < i->lo && i->hi < 'a'))
fold = false;
AddRuneRange(i->lo, i->hi, fold);
diff --git a/re2/parse.cc b/re2/parse.cc
index 4f45041..e6b27d2 100644
--- a/re2/parse.cc
+++ b/re2/parse.cc
@@ -216,6 +216,7 @@ bool Regexp::ParseState::PushRegexp(Regexp* re) {
// analysis does better with fewer character classes.
// Similarly, [Aa] can be rewritten as a literal A with ASCII case folding.
if (re->op_ == kRegexpCharClass) {
+ re->ccb_->RemoveAbove(rune_max_);
if (re->ccb_->size() == 1) {
Rune r = re->ccb_->begin()->lo;
re->Decref();
@@ -378,7 +379,6 @@ bool Regexp::ParseState::PushLiteral(Rune r) {
}
r = CycleFoldRune(r);
} while (r != r1);
- re->ccb_->RemoveAbove(rune_max_);
return PushRegexp(re);
}
@@ -1832,7 +1832,6 @@ bool Regexp::ParseState::ParseCharClass(StringPiece* s,
if (negated)
re->ccb_->Negate();
- re->ccb_->RemoveAbove(rune_max_);
*out_re = re;
return true;
diff --git a/re2/re2.cc b/re2/re2.cc
index 3a2262e..4e8af90 100644
--- a/re2/re2.cc
+++ b/re2/re2.cc
@@ -1142,7 +1142,7 @@ bool RE2::Arg::parse_uint_radix(const char* str,
return true;
}
-#ifdef RE2_HAVE_LONGLONG
+#if RE2_HAVE_LONGLONG
bool RE2::Arg::parse_longlong_radix(const char* str,
int n,
void* dest,
diff --git a/re2/re2.h b/re2/re2.h
index 6bf7ac6..bad75bb 100644
--- a/re2/re2.h
+++ b/re2/re2.h
@@ -686,7 +686,7 @@ class RE2 {
static inline Arg CRadix(unsigned int* x);
static inline Arg CRadix(long* x);
static inline Arg CRadix(unsigned long* x);
- #ifdef RE2_HAVE_LONGLONG
+ #if RE2_HAVE_LONGLONG
static inline Arg CRadix(long long* x);
static inline Arg CRadix(unsigned long long* x);
#endif
@@ -697,7 +697,7 @@ class RE2 {
static inline Arg Hex(unsigned int* x);
static inline Arg Hex(long* x);
static inline Arg Hex(unsigned long* x);
- #ifdef RE2_HAVE_LONGLONG
+ #if RE2_HAVE_LONGLONG
static inline Arg Hex(long long* x);
static inline Arg Hex(unsigned long long* x);
#endif
@@ -708,7 +708,7 @@ class RE2 {
static inline Arg Octal(unsigned int* x);
static inline Arg Octal(long* x);
static inline Arg Octal(unsigned long* x);
- #ifdef RE2_HAVE_LONGLONG
+ #if RE2_HAVE_LONGLONG
static inline Arg Octal(long long* x);
static inline Arg Octal(unsigned long long* x);
#endif
@@ -791,7 +791,7 @@ class RE2::Arg {
MAKE_PARSER(unsigned int, parse_uint);
MAKE_PARSER(long, parse_long);
MAKE_PARSER(unsigned long, parse_ulong);
- #ifdef RE2_HAVE_LONGLONG
+ #if RE2_HAVE_LONGLONG
MAKE_PARSER(long long, parse_longlong);
MAKE_PARSER(unsigned long long, parse_ulonglong);
#endif
@@ -839,7 +839,7 @@ class RE2::Arg {
DECLARE_INTEGER_PARSER(uint);
DECLARE_INTEGER_PARSER(long);
DECLARE_INTEGER_PARSER(ulong);
- #ifdef RE2_HAVE_LONGLONG
+ #if RE2_HAVE_LONGLONG
DECLARE_INTEGER_PARSER(longlong);
DECLARE_INTEGER_PARSER(ulonglong);
#endif
@@ -869,7 +869,7 @@ MAKE_INTEGER_PARSER(int, int)
MAKE_INTEGER_PARSER(unsigned int, uint)
MAKE_INTEGER_PARSER(long, long)
MAKE_INTEGER_PARSER(unsigned long, ulong)
-#ifdef RE2_HAVE_LONGLONG
+#if RE2_HAVE_LONGLONG
MAKE_INTEGER_PARSER(long long, longlong)
MAKE_INTEGER_PARSER(unsigned long long, ulonglong)
#endif
diff --git a/re2/testing/compile_test.cc b/re2/testing/compile_test.cc
index 8d92105..d438b19 100644
--- a/re2/testing/compile_test.cc
+++ b/re2/testing/compile_test.cc
@@ -99,6 +99,10 @@ static Test tests[] = {
{ "[Aa]",
"1. byte/i [61-61] -> 2\n"
"2. match! 0\n" },
+ // Issue 20992936
+ { "[[-`]",
+ "1. byte [5b-60] -> 2\n"
+ "2. match! 0\n" },
};
TEST(TestRegexpCompileToProg, Simple) {
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
index 8505195..ad15b34 100644
--- a/re2/testing/re2_test.cc
+++ b/re2/testing/re2_test.cc
@@ -1511,4 +1511,15 @@ TEST(RE2, Bug18523943) {
CHECK(!RE2::PartialMatch((const char*)a, re, &s1));
}
+TEST(RE2, Bug21371806) {
+ // Bug in parser accepting Unicode groups in Latin-1 mode,
+ // causing compiler to fail in DCHECK in prog.cc.
+
+ RE2::Options opt;
+ opt.set_encoding(RE2::Options::EncodingLatin1);
+
+ RE2 re("g\\p{Zl}]", opt);
+ CHECK(re.ok());
+}
+
} // namespace re2
diff --git a/util/util.h b/util/util.h
index 250ee93..a7ccafe 100644
--- a/util/util.h
+++ b/util/util.h
@@ -9,14 +9,14 @@
#include <stdio.h>
#include <string.h>
#include <stdint.h>
-#include <stddef.h> // For size_t
+#include <stddef.h> // For size_t
#include <assert.h>
#include <stdarg.h>
#include <time.h>
-#include <ctype.h> // For isdigit, isalpha.
+#include <ctype.h> // For isdigit, isalpha
#if !defined(WIN32)
-#include <sys/time.h> // For gettimeofday
+#include <sys/time.h> // For gettimeofday
#endif
// C++
@@ -45,7 +45,7 @@ using std::sort;
using std::swap;
using std::make_pair;
-#if defined(__GNUC__) && !defined(USE_CXX0X) && !defined(_LIBCPP_ABI_VERSION) && !defined(OS_ANDROID)
+#if defined(__GNUC__) && !defined(USE_CXX0X) && !defined(_LIBCPP_ABI_VERSION)
#include <tr1/unordered_set>
using std::tr1::unordered_set;
@@ -53,7 +53,7 @@ using std::tr1::unordered_set;
#else
#include <unordered_set>
-#if defined(WIN32) || defined(OS_ANDROID)
+#if defined(WIN32)
using std::tr1::unordered_set;
#else
using std::unordered_set;
@@ -92,13 +92,22 @@ typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned short ushort;
+// Prevent the compiler from complaining about or optimizing away variables
+// that appear unused.
+#undef ATTRIBUTE_UNUSED
+#if defined(__GNUC__)
+#define ATTRIBUTE_UNUSED __attribute__ ((unused))
+#else
+#define ATTRIBUTE_UNUSED
+#endif
+
// COMPILE_ASSERT causes a compile error about msg if expr is not true.
#if __cplusplus >= 201103L
#define COMPILE_ASSERT(expr, msg) static_assert(expr, #msg)
#else
template<bool> struct CompileAssert {};
#define COMPILE_ASSERT(expr, msg) \
- typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1]
+ typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] ATTRIBUTE_UNUSED
#endif
// DISALLOW_COPY_AND_ASSIGN disallows the copy and operator= functions.