summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2016-11-21 16:54:53 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2016-11-21 16:54:53 +0900
commitabbaebf6f92b878517d8061fae50a8b9ca84ca52 (patch)
tree6c95dcf968ab25e466822889812c9de42fcf33cc
parent73dd6e05c585d615d229f1a3af1d1a087dd50421 (diff)
downloadre2-abbaebf6f92b878517d8061fae50a8b9ca84ca52.tar.gz
re2-abbaebf6f92b878517d8061fae50a8b9ca84ca52.tar.bz2
re2-abbaebf6f92b878517d8061fae50a8b9ca84ca52.zip
Imported Upstream version 20150701upstream/20150701
Change-Id: I16f6cbaff192fa738d819450a6131af84881a96e Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
-rw-r--r--Makefile4
-rw-r--r--re2/dfa.cc18
-rw-r--r--re2/prefilter.cc3
-rw-r--r--re2/stringpiece.h1
-rw-r--r--re2/testing/re2_arg_test.cc14
-rw-r--r--re2/testing/re2_test.cc9
-rw-r--r--util/logging.h8
-rw-r--r--util/test.h5
8 files changed, 29 insertions, 33 deletions
diff --git a/Makefile b/Makefile
index fd93441..801304d 100644
--- a/Makefile
+++ b/Makefile
@@ -39,8 +39,10 @@ SONAME=0
ifeq ($(shell uname),Darwin)
MAKE_SHARED_LIBRARY=$(CXX) -dynamiclib $(LDFLAGS) -exported_symbols_list libre2.symbols.darwin
+else ifeq ($(shell uname),SunOS)
+MAKE_SHARED_LIBRARY=$(CXX) -shared -Wl,-soname,libre2.so.$(SONAME),-M,libre2.symbols $(LDFLAGS)
else
-MAKE_SHARED_LIBRARY=$(CXX) -shared -Wl,-soname,libre2.so.$(SONAME),--version-script=libre2.symbols $(LDFLAGS)
+MAKE_SHARED_LIBRARY=$(CXX) -shared -Wl,-soname,libre2.so.$(SONAME),--version-script,libre2.symbols $(LDFLAGS)
endif
INSTALL_HFILES=\
diff --git a/re2/dfa.cc b/re2/dfa.cc
index 0e567ae..25e0220 100644
--- a/re2/dfa.cc
+++ b/re2/dfa.cc
@@ -228,9 +228,8 @@ class DFA {
// sets *ismatch to true.
// L >= mutex_
void RunWorkqOnByte(Workq* q, Workq* nq,
- int c, uint flag, bool* ismatch,
- Prog::MatchKind kind,
- int new_byte_loop);
+ int c, uint flag, bool* ismatch,
+ Prog::MatchKind kind);
// Runs a Workq on a set of empty-string flags, producing a new Workq in nq.
// L >= mutex_
@@ -340,7 +339,6 @@ class DFA {
// Constant after initialization.
Prog* prog_; // The regular expression program to run.
Prog::MatchKind kind_; // The kind of DFA.
- int start_unanchored_; // start of unanchored program
bool init_failed_; // initialization failed (out of memory)
Mutex mutex_; // mutex_ >= cache_mutex_.r
@@ -443,11 +441,8 @@ DFA::DFA(Prog* prog, Prog::MatchKind kind, int64 max_mem)
if (DebugDFA)
fprintf(stderr, "\nkind %d\n%s\n", (int)kind_, prog_->DumpUnanchored().c_str());
int nmark = 0;
- start_unanchored_ = 0;
- if (kind_ == Prog::kLongestMatch) {
+ if (kind_ == Prog::kLongestMatch)
nmark = prog->size();
- start_unanchored_ = prog->start_unanchored();
- }
nastack_ = 2 * prog->size() + nmark;
// Account for space needed for DFA, q0, q1, astack.
@@ -908,8 +903,7 @@ void DFA::RunWorkqOnEmptyString(Workq* oldq, Workq* newq, uint flag) {
// regular expression program has been reached (the regexp has matched).
void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
int c, uint flag, bool* ismatch,
- Prog::MatchKind kind,
- int new_byte_loop) {
+ Prog::MatchKind kind) {
if (DEBUG_MODE)
mutex_.AssertHeld();
@@ -1033,8 +1027,8 @@ DFA::State* DFA::RunStateOnByte(State* state, int c) {
swap(q0_, q1_);
}
bool ismatch = false;
- RunWorkqOnByte(q0_, q1_, c, afterflag, &ismatch, kind_, start_unanchored_);
-
+ RunWorkqOnByte(q0_, q1_, c, afterflag, &ismatch, kind_);
+
// Most of the time, we build the state from the output of
// RunWorkqOnByte, so swap q0_ and q1_ here. However, so that
// RE2::Set can tell exactly which match instructions
diff --git a/re2/prefilter.cc b/re2/prefilter.cc
index 255923a..4a25a43 100644
--- a/re2/prefilter.cc
+++ b/re2/prefilter.cc
@@ -15,6 +15,7 @@ static const int Trace = false;
typedef set<string>::iterator SSIter;
typedef set<string>::const_iterator ConstSSIter;
+GLOBAL_MUTEX(alloc_id_mutex);
static int alloc_id = 100000; // Used for debugging.
// Initializes a Prefilter, allocating subs_ as necessary.
Prefilter::Prefilter(Op op) {
@@ -23,7 +24,9 @@ Prefilter::Prefilter(Op op) {
if (op_ == AND || op_ == OR)
subs_ = new vector<Prefilter*>;
+ GLOBAL_MUTEX_LOCK(alloc_id_mutex);
alloc_id_ = alloc_id++;
+ GLOBAL_MUTEX_UNLOCK(alloc_id_mutex);
VLOG(10) << "alloc_id: " << alloc_id_;
}
diff --git a/re2/stringpiece.h b/re2/stringpiece.h
index 37c73d1..bc8bf40 100644
--- a/re2/stringpiece.h
+++ b/re2/stringpiece.h
@@ -20,6 +20,7 @@
#define STRINGS_STRINGPIECE_H__
#include <string.h>
+#include <algorithm>
#include <cstddef>
#include <iosfwd>
#include <string>
diff --git a/re2/testing/re2_arg_test.cc b/re2/testing/re2_arg_test.cc
index f09cbee..ad6c936 100644
--- a/re2/testing/re2_arg_test.cc
+++ b/re2/testing/re2_arg_test.cc
@@ -86,22 +86,22 @@ const SuccessTable kSuccessTable[] = {
const int kNumStrings = arraysize(kSuccessTable);
-// It's ugly to use a macro, but we apparently can't use the ASSERT_TRUE_M
+// It's ugly to use a macro, but we apparently can't use the EXPECT_EQ
// macro outside of a TEST block and this seems to be the only way to
// avoid code duplication. I can also pull off a couple nice tricks
// using concatenation for the type I'm checking against.
#define PARSE_FOR_TYPE(type, column) { \
type r; \
- for ( int i = 0; i < kNumStrings; ++i ) { \
+ for (int i = 0; i < kNumStrings; ++i) { \
RE2::Arg arg(&r); \
const char* const p = kSuccessTable[i].value_string; \
bool retval = arg.Parse(p, strlen(p)); \
bool success = kSuccessTable[i].success[column]; \
- ASSERT_TRUE_M(retval == success, \
- StringPrintf("Parsing '%s' for type " #type " should return %d", \
- p, success).c_str()); \
- if ( success ) { \
- ASSERT_EQUALS(r, (type)kSuccessTable[i].value); \
+ EXPECT_EQ(retval, success) \
+ << "Parsing '" << p << "' for type " #type " should return " \
+ << success; \
+ if (success) { \
+ EXPECT_EQ(r, (type)kSuccessTable[i].value); \
} \
} \
}
diff --git a/re2/testing/re2_test.cc b/re2/testing/re2_test.cc
index ad15b34..9dd08ef 100644
--- a/re2/testing/re2_test.cc
+++ b/re2/testing/re2_test.cc
@@ -9,6 +9,7 @@
#include <sys/mman.h>
#include <sys/stat.h>
#include <errno.h>
+#include <unistd.h> /* for sysconf */
#include <vector>
#include "util/test.h"
#include "re2/re2.h"
@@ -385,8 +386,8 @@ static void TestQuoteMeta(string unquoted,
const RE2::Options& options = RE2::DefaultOptions) {
string quoted = RE2::QuoteMeta(unquoted);
RE2 re(quoted, options);
- EXPECT_TRUE_M(RE2::FullMatch(unquoted, re),
- "Unquoted='" + unquoted + "', quoted='" + quoted + "'.");
+ EXPECT_TRUE(RE2::FullMatch(unquoted, re))
+ << "Unquoted='" << unquoted << "', quoted='" << quoted << "'.";
}
// A meta-quoted string, interpreted as a pattern, should always match
@@ -395,8 +396,8 @@ static void NegativeTestQuoteMeta(string unquoted, string should_not_match,
const RE2::Options& options = RE2::DefaultOptions) {
string quoted = RE2::QuoteMeta(unquoted);
RE2 re(quoted, options);
- EXPECT_FALSE_M(RE2::FullMatch(should_not_match, re),
- "Unquoted='" + unquoted + "', quoted='" + quoted + "'.");
+ EXPECT_FALSE(RE2::FullMatch(should_not_match, re))
+ << "Unquoted='" << unquoted << "', quoted='" << quoted << "'.";
}
// Tests that quoted meta characters match their original strings,
diff --git a/util/logging.h b/util/logging.h
index b318f27..5eaf1dc 100644
--- a/util/logging.h
+++ b/util/logging.h
@@ -7,7 +7,7 @@
#ifndef RE2_UTIL_LOGGING_H__
#define RE2_UTIL_LOGGING_H__
-#include <unistd.h> /* for write */
+#include <stdio.h> /* for fwrite */
#include <sstream>
// Debug-only checking.
@@ -54,8 +54,8 @@ class LogMessage {
void Flush() {
stream() << "\n";
string s = str_.str();
- int n = (int)s.size(); // shut up msvc
- if(write(2, s.data(), n) < 0) {} // shut up gcc
+ size_t n = s.size();
+ if (fwrite(s.data(), 1, n, stderr) < n) {} // shut up gcc
flushed_ = true;
}
~LogMessage() {
@@ -64,7 +64,7 @@ class LogMessage {
}
}
ostream& stream() { return str_; }
-
+
private:
bool flushed_;
std::ostringstream str_;
diff --git a/util/test.h b/util/test.h
index d48fef0..45ca6fa 100644
--- a/util/test.h
+++ b/util/test.h
@@ -31,11 +31,6 @@ class TestRegisterer {
#define EXPECT_GE CHECK_GE
#define EXPECT_FALSE(x) CHECK(!(x))
-#define EXPECT_TRUE_M(x, y) CHECK(x) << (y)
-#define EXPECT_FALSE_M(x, y) CHECK(!(x)) << (y)
-#define ASSERT_TRUE_M(x, y) CHECK(x) << (y)
-#define ASSERT_EQUALS(x, y) CHECK_EQ(x, y)
-
const bool UsingMallocCounter = false;
namespace testing {
class MallocCounter {