mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
wasm: Compile the re2 into the library.
Disable all the logging in the library to avoid a dependency to C++ streams of the standard library. Signed-off-by: Teemu Koponen <koponen@styra.com>
This commit is contained in:
committed by
Torin Sandall
parent
7962d9933b
commit
ee7c3c16cd
+17
-2
@@ -35,6 +35,7 @@ CPPFLAGS += \
|
||||
-I src/libc++ \
|
||||
-I /usr/lib/llvm-11/include/c++/v1 \
|
||||
-I /usr/lib/llvm-11/lib/clang/11.0.0/include \
|
||||
-I src/re2 \
|
||||
-D_LIBCPP_HAS_NO_THREADS
|
||||
|
||||
ifeq ($(DEBUG), 1)
|
||||
@@ -80,6 +81,8 @@ hack:
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src/lib)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src/libmpdec)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src/libc++)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src/re2/re2)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src/re2/util)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/src)
|
||||
$(shell mkdir -p $(WASM_OBJ_DIR)/tests)
|
||||
|
||||
@@ -87,18 +90,24 @@ SRCS := $(sort $(wildcard src/*.c))
|
||||
LIB_SRCS := $(sort $(wildcard src/lib/*.c))
|
||||
LIB_MPDEC_SRCS := $(sort $(wildcard src/libmpdec/*.c))
|
||||
LIB_CPP_SRCS := $(sort $(wildcard src/libc++/*.cc))
|
||||
RE2_RE2_SRCS := $(sort $(wildcard src/re2/re2/*.cc))
|
||||
RE2_UTIL_SRCS := $(sort $(wildcard src/re2/util/*.cc))
|
||||
TEST_SRCS := $(sort $(wildcard tests/*.c))
|
||||
|
||||
-include $(patsubst %.c,$(WASM_OBJ_DIR)/%.d,$(SRCS))
|
||||
-include $(patsubst %.c,$(WASM_OBJ_DIR)/%.d,$(LIB_SRCS))
|
||||
-include $(patsubst %.c,$(WASM_OBJ_DIR)/%.d,$(LIB_MPDEC_SRCS))
|
||||
-include $(patsubst %.cc,$(WASM_OBJ_DIR)/%.d,$(LIB_CPP_SRCS))
|
||||
-include $(patsubst %.cc,$(WASM_OBJ_DIR)/%.d,$(RE2_RE2_SRCS))
|
||||
-include $(patsubst %.cc,$(WASM_OBJ_DIR)/%.d,$(RE2_UTIL_SRCS))
|
||||
-include $(patsubst %.c,$(WASM_OBJ_DIR)/%.d,$(TEST_SRCS))
|
||||
|
||||
OBJS := $(patsubst %.c, $(WASM_OBJ_DIR)/%.wasm, $(SRCS))
|
||||
LIB_OBJS := $(patsubst %.c, $(WASM_OBJ_DIR)/%.wasm, $(LIB_SRCS))
|
||||
LIB_MPDEC_OBJS := $(patsubst %.c, $(WASM_OBJ_DIR)/%.wasm, $(LIB_MPDEC_SRCS))
|
||||
LIB_CPP_OBJS := $(patsubst %.cc, $(WASM_OBJ_DIR)/%.wasm, $(LIB_CPP_SRCS))
|
||||
RE2_RE2_OBJS := $(patsubst %.cc, $(WASM_OBJ_DIR)/%.wasm, $(RE2_RE2_SRCS))
|
||||
RE2_UTIL_OBJS := $(patsubst %.cc, $(WASM_OBJ_DIR)/%.wasm, $(RE2_UTIL_SRCS))
|
||||
TEST_OBJS := $(patsubst %.c, $(WASM_OBJ_DIR)/%.wasm, $(TEST_SRCS))
|
||||
|
||||
$(OBJS): $(WASM_OBJ_DIR)/src/%.wasm: src/%.c
|
||||
@@ -113,10 +122,16 @@ $(LIB_MPDEC_OBJS): $(WASM_OBJ_DIR)/src/libmpdec/%.wasm: src/libmpdec/%.c
|
||||
$(LIB_CPP_OBJS): $(WASM_OBJ_DIR)/src/libc++/%.wasm: src/libc++/%.cc
|
||||
$(CXX) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
$(RE2_RE2_OBJS): $(WASM_OBJ_DIR)/src/re2/re2/%.wasm: src/re2/re2/%.cc
|
||||
$(CXX) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
$(RE2_UTIL_OBJS): $(WASM_OBJ_DIR)/src/re2/util/%.wasm: src/re2/util/%.cc
|
||||
$(CXX) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
$(TEST_OBJS): $(WASM_OBJ_DIR)/tests/%.wasm: tests/%.c
|
||||
$(CC) $(CFLAGS) -I src -c -o $@ $<
|
||||
|
||||
$(WASM_OBJ_DIR)/opa.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(LIB_CPP_OBJS)
|
||||
$(WASM_OBJ_DIR)/opa.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(LIB_CPP_OBJS) $(RE2_RE2_OBJS) $(RE2_UTIL_OBJS)
|
||||
wasm-ld-11 \
|
||||
--allow-undefined-file=src/undefined.symbols \
|
||||
--import-memory \
|
||||
@@ -125,7 +140,7 @@ $(WASM_OBJ_DIR)/opa.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(LIB_CPP_OBJS)
|
||||
-o $@ $^
|
||||
@wasm2wat $(WASM_OBJ_DIR)/opa.wasm > $(WASM_OBJ_DIR)/opa.wast
|
||||
|
||||
$(WASM_OBJ_DIR)/opa-test.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(LIB_CPP_OBJS) $(TEST_OBJS)
|
||||
$(WASM_OBJ_DIR)/opa-test.wasm: $(OBJS) $(LIB_OBJS) $(LIB_MPDEC_OBJS) $(LIB_CPP_OBJS) $(RE2_RE2_OBJS) $(RE2_UTIL_OBJS) $(TEST_OBJS)
|
||||
@cat src/undefined.symbols tests/undefined.symbols > _obj/undefined.symbols
|
||||
@wasm-ld-11 \
|
||||
--allow-undefined-file=_obj/undefined.symbols \
|
||||
|
||||
@@ -108,9 +108,11 @@ void BitState::Push(int id, const char* p) {
|
||||
if (njob_ >= job_.size()) {
|
||||
GrowStack();
|
||||
if (njob_ >= job_.size()) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "GrowStack() failed: "
|
||||
<< "njob_ = " << njob_ << ", "
|
||||
<< "job_.size() = " << job_.size();
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -168,7 +170,9 @@ bool BitState::TrySearch(int id0, const char* p0) {
|
||||
Prog::Inst* ip = prog_->inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected opcode: " << ip->opcode();
|
||||
#endif
|
||||
return false;
|
||||
|
||||
case kInstFail:
|
||||
|
||||
@@ -592,7 +592,9 @@ Frag Compiler::FindByteRange(int root, int id) {
|
||||
return NoMatch();
|
||||
}
|
||||
|
||||
#if 0
|
||||
LOG(DFATAL) << "should never happen";
|
||||
#endif
|
||||
return NoMatch();
|
||||
}
|
||||
|
||||
@@ -769,7 +771,9 @@ void Compiler::AddRuneRangeUTF8(Rune lo, Rune hi, bool foldcase) {
|
||||
// Should not be called.
|
||||
Frag Compiler::Copy(Frag arg) {
|
||||
// We're using WalkExponential; there should be no copying.
|
||||
#if 0
|
||||
LOG(DFATAL) << "Compiler::Copy called!";
|
||||
#endif
|
||||
failed_ = true;
|
||||
return NoMatch();
|
||||
}
|
||||
@@ -896,7 +900,9 @@ Frag Compiler::PostVisit(Regexp* re, Frag, Frag, Frag* child_frags,
|
||||
CharClass* cc = re->cc();
|
||||
if (cc->empty()) {
|
||||
// This can't happen.
|
||||
#if 0
|
||||
LOG(DFATAL) << "No ranges in char class";
|
||||
#endif
|
||||
failed_ = true;
|
||||
return NoMatch();
|
||||
}
|
||||
@@ -954,7 +960,9 @@ Frag Compiler::PostVisit(Regexp* re, Frag, Frag, Frag* child_frags,
|
||||
case kRegexpNoWordBoundary:
|
||||
return EmptyWidth(kEmptyNonWordBoundary);
|
||||
}
|
||||
#if 0
|
||||
LOG(DFATAL) << "Missing case in Compiler: " << re->op();
|
||||
#endif
|
||||
failed_ = true;
|
||||
return NoMatch();
|
||||
}
|
||||
|
||||
@@ -847,7 +847,9 @@ void DFA::AddToQueue(Workq* q, int id, uint32_t flag) {
|
||||
Prog::Inst* ip = prog_->inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstByteRange: // just save these on the queue
|
||||
@@ -936,7 +938,9 @@ void DFA::RunWorkqOnByte(Workq* oldq, Workq* newq,
|
||||
Prog::Inst* ip = prog_->inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstFail: // never succeeds
|
||||
@@ -1004,14 +1008,20 @@ DFA::State* DFA::RunStateOnByte(State* state, int c) {
|
||||
return FullMatchState;
|
||||
}
|
||||
if (state == DeadState) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "DeadState in RunStateOnByte";
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
if (state == NULL) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "NULL state in RunStateOnByte";
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected special state in RunStateOnByte";
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1241,8 +1251,10 @@ DFA::State* DFA::StateSaver::Restore() {
|
||||
return special_;
|
||||
MutexLock l(&dfa_->mutex_);
|
||||
State* s = dfa_->CachedState(inst_, ninst_, flag_);
|
||||
#if 0
|
||||
if (s == NULL)
|
||||
LOG(DFATAL) << "StateSaver failed to restore state.";
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -1432,7 +1444,9 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) {
|
||||
}
|
||||
ns = RunStateOnByteUnlocked(s, c);
|
||||
if (ns == NULL) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "RunStateOnByteUnlocked failed after ResetCache";
|
||||
#endif
|
||||
params->failed = true;
|
||||
return false;
|
||||
}
|
||||
@@ -1504,7 +1518,9 @@ inline bool DFA::InlinedSearchLoop(SearchParams* params) {
|
||||
}
|
||||
ns = RunStateOnByteUnlocked(s, lastbyte);
|
||||
if (ns == NULL) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "RunStateOnByteUnlocked failed after Reset";
|
||||
#endif
|
||||
params->failed = true;
|
||||
return false;
|
||||
}
|
||||
@@ -1621,7 +1637,9 @@ bool DFA::AnalyzeSearch(SearchParams* params) {
|
||||
|
||||
// Sanity check: make sure that text lies within context.
|
||||
if (text.begin() < context.begin() || text.end() > context.end()) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "context does not contain text";
|
||||
#endif
|
||||
params->start = DeadState;
|
||||
return true;
|
||||
}
|
||||
@@ -1668,7 +1686,9 @@ bool DFA::AnalyzeSearch(SearchParams* params) {
|
||||
if (!AnalyzeSearchHelper(params, info, flags)) {
|
||||
ResetCache(params->cache_lock);
|
||||
if (!AnalyzeSearchHelper(params, info, flags)) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Failed to analyze start state.";
|
||||
#endif
|
||||
params->failed = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -239,7 +239,9 @@ void NFA::AddToThreadq(Threadq* q, int id0, int c, const StringPiece& context,
|
||||
Prog::Inst* ip = prog_->inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled " << ip->opcode() << " in AddToThreadq";
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstFail:
|
||||
@@ -351,7 +353,9 @@ int NFA::Step(Threadq* runq, Threadq* nextq, int c, const StringPiece& context,
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
// Should only see the values handled below.
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unhandled " << ip->opcode() << " in step";
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstByteRange:
|
||||
@@ -457,7 +461,9 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
||||
|
||||
// Sanity check: make sure that text lies within context.
|
||||
if (text.begin() < context.begin() || text.end() > context.end()) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "context does not contain text";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -472,7 +478,9 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
||||
}
|
||||
|
||||
if (nsubmatch < 0) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Bad args: nsubmatch=" << nsubmatch;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -540,7 +548,9 @@ bool NFA::Search(const StringPiece& text, const StringPiece& const_context,
|
||||
Prog::Inst* ip = prog_->inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected opcode in short circuit: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstCapture:
|
||||
@@ -671,7 +681,9 @@ void Prog::Fanout(SparseArray<int>* fanout) {
|
||||
Prog::Inst* ip = inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled " << ip->opcode() << " in Prog::Fanout()";
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstByteRange:
|
||||
|
||||
@@ -216,7 +216,9 @@ bool Prog::SearchOnePass(const StringPiece& text,
|
||||
Anchor anchor, MatchKind kind,
|
||||
StringPiece* match, int nmatch) {
|
||||
if (anchor != kAnchored && kind != kFullMatch) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Cannot use SearchOnePass for unanchored matches.";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -444,7 +446,9 @@ bool Prog::IsOnePass() {
|
||||
Prog::Inst* ip = inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstAltMatch:
|
||||
@@ -461,9 +465,11 @@ bool Prog::IsOnePass() {
|
||||
int nextindex = nodebyid[ip->out()];
|
||||
if (nextindex == -1) {
|
||||
if (nalloc >= maxnodes) {
|
||||
#if 0
|
||||
if (ExtraDebug)
|
||||
LOG(ERROR) << StringPrintf(
|
||||
"Not OnePass: hit node limit %d >= %d", nalloc, maxnodes);
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
nextindex = nalloc;
|
||||
@@ -486,9 +492,11 @@ bool Prog::IsOnePass() {
|
||||
if ((act & kImpossible) == kImpossible) {
|
||||
node->action[b] = newact;
|
||||
} else if (act != newact) {
|
||||
#if 0
|
||||
if (ExtraDebug)
|
||||
LOG(ERROR) << StringPrintf(
|
||||
"Not OnePass: conflict on byte %#x at state %d", c, *it);
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -507,9 +515,11 @@ bool Prog::IsOnePass() {
|
||||
if ((act & kImpossible) == kImpossible) {
|
||||
node->action[b] = newact;
|
||||
} else if (act != newact) {
|
||||
#if 0
|
||||
if (ExtraDebug)
|
||||
LOG(ERROR) << StringPrintf(
|
||||
"Not OnePass: conflict on byte %#x at state %d", c, *it);
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
@@ -548,9 +558,11 @@ bool Prog::IsOnePass() {
|
||||
|
||||
// If already on work queue, (1) is violated: bail out.
|
||||
if (!AddQ(&workq, ip->out())) {
|
||||
#if 0
|
||||
if (ExtraDebug)
|
||||
LOG(ERROR) << StringPrintf(
|
||||
"Not OnePass: multiple paths %d -> %d", *it, ip->out());
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
id = ip->out();
|
||||
@@ -559,9 +571,11 @@ bool Prog::IsOnePass() {
|
||||
case kInstMatch:
|
||||
if (matched) {
|
||||
// (3) is violated
|
||||
#if 0
|
||||
if (ExtraDebug)
|
||||
LOG(ERROR) << StringPrintf(
|
||||
"Not OnePass: multiple matches from %d", *it);
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
matched = true;
|
||||
@@ -581,6 +595,7 @@ bool Prog::IsOnePass() {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (ExtraDebug) { // For debugging, dump one-pass NFA to LOG(ERROR).
|
||||
LOG(ERROR) << "bytemap:\n" << DumpByteMap();
|
||||
LOG(ERROR) << "prog:\n" << Dump();
|
||||
@@ -610,6 +625,7 @@ bool Prog::IsOnePass() {
|
||||
}
|
||||
LOG(ERROR) << "nodes:\n" << dump;
|
||||
}
|
||||
#endif
|
||||
|
||||
dfa_mem_ -= nalloc*statesize;
|
||||
onepass_nodes_ = PODArray<uint8_t>(nalloc*statesize);
|
||||
|
||||
@@ -348,7 +348,9 @@ static void AddFoldedRange(CharClassBuilder* cc, Rune lo, Rune hi, int depth) {
|
||||
// current Unicode tables. make_unicode_casefold.py checks that
|
||||
// the cycles are not too long, and we double-check here using depth.
|
||||
if (depth > 10) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "AddFoldedRange recurses too much.";
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -557,8 +559,10 @@ int RepetitionWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg,
|
||||
|
||||
int RepetitionWalker::ShortVisit(Regexp* re, int parent_arg) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "RepetitionWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -844,7 +848,9 @@ void Regexp::RemoveLeadingString(Regexp* re, int n) {
|
||||
case 0:
|
||||
case 1:
|
||||
// Impossible.
|
||||
#if 0
|
||||
LOG(DFATAL) << "Concat of " << re->nsub();
|
||||
#endif
|
||||
re->submany_ = NULL;
|
||||
re->op_ = kRegexpEmptyMatch;
|
||||
break;
|
||||
@@ -974,7 +980,9 @@ int Regexp::FactorAlternation(Regexp** sub, int nsub, ParseFlags flags) {
|
||||
i += iter->nsub;
|
||||
break;
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unknown round: " << round;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
// If we are done, copy until the end of sub.
|
||||
@@ -1013,7 +1021,9 @@ int Regexp::FactorAlternation(Regexp** sub, int nsub, ParseFlags flags) {
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unknown round: " << round;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1180,8 +1190,10 @@ void FactorAlternationImpl::Round3(Regexp** sub, int nsub,
|
||||
} else if (re->op() == kRegexpLiteral) {
|
||||
ccb.AddRangeFlags(re->rune(), re->rune(), re->parse_flags());
|
||||
} else {
|
||||
#if 0
|
||||
LOG(DFATAL) << "RE2: unexpected op: " << re->op() << " "
|
||||
<< re->ToString();
|
||||
#endif
|
||||
}
|
||||
re->Decref();
|
||||
}
|
||||
@@ -1439,7 +1451,9 @@ static int UnHex(int c) {
|
||||
return c - 'A' + 10;
|
||||
if ('a' <= c && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
#if 0
|
||||
LOG(DFATAL) << "Bad hex digit " << c;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1585,7 +1599,9 @@ static bool ParseEscape(StringPiece* s, Rune* rp,
|
||||
// return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
LOG(DFATAL) << "Not reached in ParseEscape.";
|
||||
#endif
|
||||
|
||||
BadEscape:
|
||||
// Unrecognized escape sequence.
|
||||
@@ -2040,7 +2056,9 @@ bool Regexp::ParseState::ParsePerlFlags(StringPiece* s) {
|
||||
|
||||
// Caller is supposed to check this.
|
||||
if (!(flags_ & PerlX) || t.size() < 2 || t[0] != '(' || t[1] != '?') {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Bad call to ParseState::ParsePerlFlags";
|
||||
#endif
|
||||
status_->set_code(kRegexpInternalError);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,9 @@ static bool IsMatch(Prog* prog, Prog::Inst* ip) {
|
||||
for (;;) {
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected opcode in IsMatch: " << ip->opcode();
|
||||
#endif
|
||||
return false;
|
||||
|
||||
case kInstAlt:
|
||||
@@ -509,12 +511,14 @@ void Prog::ComputeByteMap() {
|
||||
|
||||
builder.Build(bytemap_, &bytemap_range_);
|
||||
|
||||
#if 0
|
||||
if (0) { // For debugging, use trivial bytemap.
|
||||
LOG(ERROR) << "Using trivial bytemap.";
|
||||
for (int i = 0; i < 256; i++)
|
||||
bytemap_[i] = static_cast<uint8_t>(i);
|
||||
bytemap_range_ = 256;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Prog::Flatten() implements a graph rewriting algorithm.
|
||||
@@ -668,7 +672,9 @@ void Prog::MarkSuccessors(SparseArray<int>* rootmap,
|
||||
Inst* ip = inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstAltMatch:
|
||||
@@ -728,7 +734,9 @@ void Prog::MarkDominator(int root, SparseArray<int>* rootmap,
|
||||
Inst* ip = inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstAltMatch:
|
||||
@@ -795,7 +803,9 @@ void Prog::EmitList(int root, SparseArray<int>* rootmap,
|
||||
Inst* ip = inst(id);
|
||||
switch (ip->opcode()) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "unhandled opcode: " << ip->opcode();
|
||||
#endif
|
||||
break;
|
||||
|
||||
case kInstAltMatch:
|
||||
|
||||
@@ -130,8 +130,10 @@ int RE2::Options::ParseFlags() const {
|
||||
int flags = Regexp::ClassNL;
|
||||
switch (encoding()) {
|
||||
default:
|
||||
#if 0
|
||||
if (log_errors())
|
||||
LOG(ERROR) << "Unknown encoding " << encoding();
|
||||
#endif
|
||||
break;
|
||||
case RE2::Options::EncodingUTF8:
|
||||
break;
|
||||
@@ -201,10 +203,12 @@ void RE2::Init(const StringPiece& pattern, const Options& options) {
|
||||
static_cast<Regexp::ParseFlags>(options_.ParseFlags()),
|
||||
&status);
|
||||
if (entire_regexp_ == NULL) {
|
||||
#if 0
|
||||
if (options_.log_errors()) {
|
||||
LOG(ERROR) << "Error parsing '" << trunc(pattern_) << "': "
|
||||
<< status.Text();
|
||||
}
|
||||
#endif
|
||||
error_ = new std::string(status.Text());
|
||||
error_code_ = RegexpErrorToRE2(status.code());
|
||||
error_arg_ = std::string(status.error_arg());
|
||||
@@ -222,8 +226,10 @@ void RE2::Init(const StringPiece& pattern, const Options& options) {
|
||||
// Prog has two DFAs but the reverse prog has one.
|
||||
prog_ = suffix_regexp_->CompileToProg(options_.max_mem()*2/3);
|
||||
if (prog_ == NULL) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "Error compiling '" << trunc(pattern_) << "'";
|
||||
#endif
|
||||
error_ = new std::string("pattern too large - compile failed");
|
||||
error_code_ = RE2::ErrorPatternTooLarge;
|
||||
return;
|
||||
@@ -248,8 +254,10 @@ re2::Prog* RE2::ReverseProg() const {
|
||||
re->rprog_ =
|
||||
re->suffix_regexp_->CompileToReverseProg(re->options_.max_mem() / 3);
|
||||
if (re->rprog_ == NULL) {
|
||||
#if 0
|
||||
if (re->options_.log_errors())
|
||||
LOG(ERROR) << "Error reverse compiling '" << trunc(re->pattern_) << "'";
|
||||
#endif
|
||||
// We no longer touch error_ and error_code_ because failing to compile
|
||||
// the reverse Prog is not a showstopper: falling back to NFA execution
|
||||
// is fine. More importantly, an RE2 object is supposed to be logically
|
||||
@@ -620,17 +628,21 @@ bool RE2::Match(const StringPiece& text,
|
||||
StringPiece* submatch,
|
||||
int nsubmatch) const {
|
||||
if (!ok()) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "Invalid RE2: " << *error_;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
if (startpos > endpos || endpos > text.size()) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "RE2: invalid startpos, endpos pair. ["
|
||||
<< "startpos: " << startpos << ", "
|
||||
<< "endpos: " << endpos << ", "
|
||||
<< "text size: " << text.size() << "]";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -707,7 +719,9 @@ bool RE2::Match(const StringPiece& text,
|
||||
bool skipped_test = false;
|
||||
switch (re_anchor) {
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected re_anchor value: " << re_anchor;
|
||||
#endif
|
||||
return false;
|
||||
|
||||
case UNANCHORED: {
|
||||
@@ -724,12 +738,14 @@ bool RE2::Match(const StringPiece& text,
|
||||
if (!prog->SearchDFA(subtext, text, Prog::kAnchored,
|
||||
Prog::kLongestMatch, matchp, &dfa_failed, NULL)) {
|
||||
if (dfa_failed) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "DFA out of memory: "
|
||||
<< "pattern length " << pattern_.size() << ", "
|
||||
<< "program size " << prog->size() << ", "
|
||||
<< "list count " << prog->list_count() << ", "
|
||||
<< "bytemap range " << prog->bytemap_range();
|
||||
#endif
|
||||
// Fall back to NFA below.
|
||||
skipped_test = true;
|
||||
break;
|
||||
@@ -744,12 +760,14 @@ bool RE2::Match(const StringPiece& text,
|
||||
if (!prog_->SearchDFA(subtext, text, anchor, kind,
|
||||
matchp, &dfa_failed, NULL)) {
|
||||
if (dfa_failed) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "DFA out of memory: "
|
||||
<< "pattern length " << pattern_.size() << ", "
|
||||
<< "program size " << prog_->size() << ", "
|
||||
<< "list count " << prog_->list_count() << ", "
|
||||
<< "bytemap range " << prog_->bytemap_range();
|
||||
#endif
|
||||
// Fall back to NFA below.
|
||||
skipped_test = true;
|
||||
break;
|
||||
@@ -770,18 +788,22 @@ bool RE2::Match(const StringPiece& text,
|
||||
if (!prog->SearchDFA(match, text, Prog::kAnchored,
|
||||
Prog::kLongestMatch, &match, &dfa_failed, NULL)) {
|
||||
if (dfa_failed) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "DFA out of memory: "
|
||||
<< "pattern length " << pattern_.size() << ", "
|
||||
<< "program size " << prog->size() << ", "
|
||||
<< "list count " << prog->list_count() << ", "
|
||||
<< "bytemap range " << prog->bytemap_range();
|
||||
#endif
|
||||
// Fall back to NFA below.
|
||||
skipped_test = true;
|
||||
break;
|
||||
}
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "SearchDFA inconsistency";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
@@ -812,12 +834,14 @@ bool RE2::Match(const StringPiece& text,
|
||||
if (!prog_->SearchDFA(subtext, text, anchor, kind,
|
||||
&match, &dfa_failed, NULL)) {
|
||||
if (dfa_failed) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "DFA out of memory: "
|
||||
<< "pattern length " << pattern_.size() << ", "
|
||||
<< "program size " << prog_->size() << ", "
|
||||
<< "list count " << prog_->list_count() << ", "
|
||||
<< "bytemap range " << prog_->bytemap_range();
|
||||
#endif
|
||||
// Fall back to NFA below.
|
||||
skipped_test = true;
|
||||
break;
|
||||
@@ -848,21 +872,27 @@ bool RE2::Match(const StringPiece& text,
|
||||
|
||||
if (can_one_pass && anchor != Prog::kUnanchored) {
|
||||
if (!prog_->SearchOnePass(subtext1, text, anchor, kind, submatch, ncap)) {
|
||||
#if 0
|
||||
if (!skipped_test && options_.log_errors())
|
||||
LOG(ERROR) << "SearchOnePass inconsistency";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} else if (can_bit_state && subtext1.size() <= bit_state_text_max) {
|
||||
if (!prog_->SearchBitState(subtext1, text, anchor,
|
||||
kind, submatch, ncap)) {
|
||||
#if 0
|
||||
if (!skipped_test && options_.log_errors())
|
||||
LOG(ERROR) << "SearchBitState inconsistency";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!prog_->SearchNFA(subtext1, text, anchor, kind, submatch, ncap)) {
|
||||
#if 0
|
||||
if (!skipped_test && options_.log_errors())
|
||||
LOG(ERROR) << "SearchNFA inconsistency";
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -886,8 +916,10 @@ bool RE2::DoMatch(const StringPiece& text,
|
||||
const Arg* const* args,
|
||||
int n) const {
|
||||
if (!ok()) {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "Invalid RE2: " << *error_;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1018,10 +1050,12 @@ bool RE2::Rewrite(std::string* out,
|
||||
if (isdigit(c)) {
|
||||
int n = (c - '0');
|
||||
if (n >= veclen) {
|
||||
#if 0
|
||||
if (options_.log_errors()) {
|
||||
LOG(ERROR) << "invalid substitution \\" << n
|
||||
<< " from " << veclen << " groups";
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
StringPiece snip = vec[n];
|
||||
@@ -1030,14 +1064,17 @@ bool RE2::Rewrite(std::string* out,
|
||||
} else if (c == '\\') {
|
||||
out->push_back('\\');
|
||||
} else {
|
||||
#if 0
|
||||
if (options_.log_errors())
|
||||
LOG(ERROR) << "invalid rewrite pattern: " << rewrite.data();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/***** Parsers for various types *****/
|
||||
|
||||
namespace re2_internal {
|
||||
@@ -1290,6 +1327,7 @@ bool Parse(const char* str, size_t n, unsigned long long* dest, int radix) {
|
||||
}
|
||||
|
||||
} // namespace re2_internal
|
||||
#endif
|
||||
|
||||
namespace hooks {
|
||||
|
||||
|
||||
@@ -44,8 +44,10 @@ Regexp::Regexp(RegexpOp op, ParseFlags parse_flags)
|
||||
// that could cause arbitrarily deep recursion, so
|
||||
// required Decref() to have handled them for us.
|
||||
Regexp::~Regexp() {
|
||||
#if 0
|
||||
if (nsub_ > 0)
|
||||
LOG(DFATAL) << "Regexp not destroyed.";
|
||||
#endif
|
||||
|
||||
switch (op_) {
|
||||
default:
|
||||
@@ -143,8 +145,10 @@ void Regexp::Destroy() {
|
||||
while (stack != NULL) {
|
||||
Regexp* re = stack;
|
||||
stack = re->down_;
|
||||
#if 0
|
||||
if (re->ref_ != 0)
|
||||
LOG(DFATAL) << "Bad reference count " << re->ref_;
|
||||
#endif
|
||||
if (re->nsub_ > 0) {
|
||||
Regexp** subs = re->sub();
|
||||
for (int i = 0; i < re->nsub_; i++) {
|
||||
@@ -405,7 +409,9 @@ static bool TopEqual(Regexp* a, Regexp* b) {
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
LOG(DFATAL) << "Unexpected op in Regexp::Equal: " << a->op();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -545,8 +551,10 @@ class NumCapturesWalker : public Regexp::Walker<Ignored> {
|
||||
|
||||
virtual Ignored ShortVisit(Regexp* re, Ignored ignored) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "NumCapturesWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return ignored;
|
||||
}
|
||||
@@ -593,8 +601,10 @@ class NamedCapturesWalker : public Regexp::Walker<Ignored> {
|
||||
|
||||
virtual Ignored ShortVisit(Regexp* re, Ignored ignored) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "NamedCapturesWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return ignored;
|
||||
}
|
||||
@@ -637,8 +647,10 @@ class CaptureNamesWalker : public Regexp::Walker<Ignored> {
|
||||
|
||||
virtual Ignored ShortVisit(Regexp* re, Ignored ignored) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "CaptureNamesWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return ignored;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,9 @@ bool Regexp::ComputeSimple() {
|
||||
case kRegexpRepeat:
|
||||
return false;
|
||||
}
|
||||
#if 0
|
||||
LOG(DFATAL) << "Case not handled in ComputeSimple: " << op_;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -221,8 +223,10 @@ Regexp* CoalesceWalker::Copy(Regexp* re) {
|
||||
|
||||
Regexp* CoalesceWalker::ShortVisit(Regexp* re, Regexp* parent_arg) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "CoalesceWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return re->Incref();
|
||||
}
|
||||
@@ -371,7 +375,9 @@ void CoalesceWalker::DoCoalesce(Regexp** r1ptr, Regexp** r2ptr) {
|
||||
break;
|
||||
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "DoCoalesce failed: r1->op() is " << r1->op();
|
||||
#endif
|
||||
nre->Decref();
|
||||
return;
|
||||
}
|
||||
@@ -432,7 +438,9 @@ void CoalesceWalker::DoCoalesce(Regexp** r1ptr, Regexp** r2ptr) {
|
||||
}
|
||||
|
||||
default:
|
||||
#if 0
|
||||
LOG(DFATAL) << "DoCoalesce failed: r2->op() is " << r2->op();
|
||||
#endif
|
||||
nre->Decref();
|
||||
return;
|
||||
}
|
||||
@@ -447,8 +455,10 @@ Regexp* SimplifyWalker::Copy(Regexp* re) {
|
||||
|
||||
Regexp* SimplifyWalker::ShortVisit(Regexp* re, Regexp* parent_arg) {
|
||||
// Should never be called: we use Walk(), not WalkExponential().
|
||||
#if 0
|
||||
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||
LOG(DFATAL) << "SimplifyWalker::ShortVisit called";
|
||||
#endif
|
||||
#endif
|
||||
return re->Incref();
|
||||
}
|
||||
@@ -564,7 +574,9 @@ Regexp* SimplifyWalker::PostVisit(Regexp* re,
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
LOG(ERROR) << "Simplify case not handled: " << re->op();
|
||||
#endif
|
||||
return re->Incref();
|
||||
}
|
||||
|
||||
@@ -641,7 +653,9 @@ Regexp* SimplifyWalker::SimplifyRepeat(Regexp* re, int min, int max,
|
||||
if (nre == NULL) {
|
||||
// Some degenerate case, like min > max, or min < max < 0.
|
||||
// This shouldn't happen, because the parser rejects such regexps.
|
||||
#if 0
|
||||
LOG(DFATAL) << "Malformed repeat " << re->ToString() << " " << min << " " << max;
|
||||
#endif
|
||||
return new Regexp(kRegexpNoMatch, f);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,9 +57,11 @@ StringPiece::size_type StringPiece::rfind(char c, size_type pos) const {
|
||||
return npos;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::ostream& operator<<(std::ostream& o, const StringPiece& p) {
|
||||
o.write(p.data(), p.size());
|
||||
return o;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace re2
|
||||
|
||||
@@ -101,8 +101,10 @@ int ToStringWalker::PreVisit(Regexp* re, int parent_arg, bool* stop) {
|
||||
|
||||
case kRegexpCapture:
|
||||
t_->append("(");
|
||||
#if 0
|
||||
if (re->cap() == 0)
|
||||
LOG(DFATAL) << "kRegexpCapture cap() == 0";
|
||||
#endif
|
||||
if (re->name()) {
|
||||
t_->append("?P<");
|
||||
t_->append(*re->name());
|
||||
@@ -184,8 +186,10 @@ int ToStringWalker::PostVisit(Regexp* re, int parent_arg, int pre_arg,
|
||||
// at the end of their strings, so just remove the last one.
|
||||
if ((*t_)[t_->size()-1] == '|')
|
||||
t_->erase(t_->size()-1);
|
||||
#if 0
|
||||
else
|
||||
LOG(DFATAL) << "Bad final char: " << t_;
|
||||
#endif
|
||||
if (prec < PrecAlternate)
|
||||
t_->append(")");
|
||||
break;
|
||||
|
||||
@@ -146,7 +146,9 @@ template<typename T> Regexp::Walker<T>::~Walker() {
|
||||
// Logs DFATAL if stack is not already clear.
|
||||
template<typename T> void Regexp::Walker<T>::Reset() {
|
||||
if (!stack_.empty()) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Stack not empty.";
|
||||
#endif
|
||||
while (!stack_.empty()) {
|
||||
delete[] stack_.top().child_args;
|
||||
stack_.pop();
|
||||
@@ -159,7 +161,9 @@ template<typename T> T Regexp::Walker<T>::WalkInternal(Regexp* re, T top_arg,
|
||||
Reset();
|
||||
|
||||
if (re == NULL) {
|
||||
#if 0
|
||||
LOG(DFATAL) << "Walk NULL";
|
||||
#endif
|
||||
return top_arg;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#if 0
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
#include "util/util.h"
|
||||
|
||||
@@ -54,6 +56,7 @@
|
||||
|
||||
#define VLOG(x) if((x)>0){}else LOG_INFO.stream()
|
||||
|
||||
#if 0
|
||||
class LogMessage {
|
||||
public:
|
||||
LogMessage(const char* file, int line)
|
||||
@@ -106,4 +109,6 @@ class LogMessageFatal : public LogMessage {
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // UTIL_LOGGING_H_
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ function report(passed, error, msg) {
|
||||
|
||||
async function test(executable) {
|
||||
|
||||
const mem = new WebAssembly.Memory({ initial: 2 });
|
||||
const mem = new WebAssembly.Memory({ initial: 3 });
|
||||
const addr2string = stringDecoder(mem);
|
||||
|
||||
let cache = {};
|
||||
|
||||
Reference in New Issue
Block a user