-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build errors in MSVC 2015 #99
Comments
D'oh! I checked MSDN (https://msdn.microsoft.com/en-us/library/b6fae073.aspx) before I made that change in order to have some assurance that it would work with MSVC, but there must be more to it. :( |
Could you please try adding |
I'll try it, but remember that dfa.cc got an error (not a warning) on line 729 and I doubt if suppressing the warning will suppress the error. |
If MSVC still has a problem with the initialisation, maybe try just declaring |
On 7/2/2016 6:10 AM, Paul Wankadia wrote:
|
This is line 729:
If it turns out that disabling the warning isn't enough, then you could perhaps try this instead:
That would reveal whether it's just the form of the initialisation that's upsetting MSVC. |
On 7/3/2016 3:06 AM, Paul Wankadia wrote:
// Copyright 2008 The RE2 Authors. All Rights Reserved. // Tested by search_test.cc. #include <string.h> namespace re2 { static const int Debug = 0; // The key insight behind this implementation is that the // A state in the one-pass NFA - just an array of actions indexed // The uint32 conditions in the action are a combination of static const int kIndexShift = 16; // number of bits below index // Parameters used to skip over cap[0], cap[1]. static const uint32 kMatchWins = 1 << kEmptyShift; static const uint32 kImpossible = kEmptyWordBoundary | kEmptyNonWordBoundary; // Check, at compile time, that prog.h agrees with math above. static bool Satisfy(uint32 cond, const StringPiece& context, const char* p) { // Apply the capture bits in cond, saving p to the appropriate // Compute a node pointer. bool Prog::SearchOnePass(const StringPiece& text, // Make sure we have at least cap[1], const char* cap[kMaxCap]; const char* matchcap[kMaxCap]; StringPiece context = const_context; // State and act are marked volatile to
skipmatch: // Look for match at end of input. done: // Analysis to determine whether a given regexp program is one-pass. // If ip is not on workq, adds ip to work queue and returns true. struct InstCond { // Returns whether this is a one-pass program; that is, if (start() == 0) // no match // Steal memory for the one-pass NFA from the overall DFA budget. // Flood the graph starting at the start state, and check int size = this->size(); uint8* nodes = new uint8[maxnodes_statesize]; Instq tovisit(size), workq(size);
} if (Debug) { // For debugging, dump one-pass NFA to LOG(ERROR).
} // Overallocated earlier; cut down to actual size. onepass_start_ = IndexToNode(nodes, statesize, nodebyid[start()]); delete[] stack; fail: } // namespace re2 // Copyright 2008 The RE2 Authors. All Rights Reserved. // A DFA (deterministic finite automaton)-based regular expression search. #include "util/flags.h" DEFINE_bool(re2_dfa_bail_when_slow, true, namespace re2 { #if !defined(linux) /* only Linux seems to have memrchr / return NULL; // Changing this to true compiles in prints that trace execution of the DFA. // A DFA implementation of a regular expression program. // Searches for the regular expression in text, which is considered // Builds out all states for the entire DFA. FOR TESTING ONLY // Computes min and max for matching strings. Won't return strings // These data structures are logically private, but C++ makes it too // A single DFA state. The DFA is represented as a graph of these
#ifdef MSC_VER enum {
}; #ifndef STL_MSVC #ifdef STL_MSVC private: enum {
}; // Resets the DFA State cache, flushing all saved State* information. // Looks up and returns the State corresponding to a Workq. // Looks up and returns a State matching the inst, ninst, and flag. // Clear the cache entirely. // Converts a State into a Workq: the opposite of WorkqToCachedState. // Runs a State on a given byte, returning the next state. // Runs a Workq on a given byte followed by a set of empty-string flags, // Runs a Workq on a set of empty-string flags, producing a new Workq in nq. // Adds the instruction id to the Workq, following empty arrows // For debugging, returns a text representation of State. // For debugging, returns a text representation of a Workq. // Search parameters
private: // Before each search, the parameters to Search are analyzed by // Fills in params->start and params->firstbyte using // The generic search loop, inlined to create specialized versions. // The specialized versions of InlinedSearchLoop. The three letters // The main search loop: calls an appropriate specialized version of // For debugging, a slow search loop that calls InlinedSearchLoop // Looks up bytes in bytemap_ but handles case c == kByteEndText too. // Constant after initialization. Mutex mutex_; // mutex_ >= cache_mutex_.r // Scratch areas, protected by mutex_. // State* cache. Many threads use and add to the cache simultaneously, // Shorthand for casting to uint8_. // Work queues // Marks separate thread groups of different priority // Internally, the DFA uses a sparse array of bool is_mark(int i) { return i >= n_; } int maxmark() { return maxmark_; } void clear() { void mark() { int size() { void insert(int id) { void insert_new(int id) { private: DFA::DFA(Prog* prog, Prog::MatchKind kind, int64 max_mem) // Account for space needed for DFA, q0, q1, astack. state_budget_ = mem_budget_; // Make sure there is a reasonable amount of working room left. q0_ = new Workq(prog_->size(), nmark); DFA::~DFA() { // In the DFA state graph, s->next[c] == NULL means that the // Signals that the rest of the string matches no matter what it is. #define SpecialStateMax FullMatchState // Debugging printouts // For debugging, returns a string representation of the work queue. // For debugging, returns a string representation of the state. ////////////////////////////////////////////////////////////////////// // NOTE(rsc): The choice of State construction determines whether the DFA // Looks in the State cache for a State matching q, flag. // Construct array of instruction ids for the new state. // If there are no empty-width instructions waiting to execute, // NOTE(rsc): The code above cannot do flag &= needflags, // If there are no Insts in the list, it's a dead state, // If we're in longest match mode, the state is a sequence of // Save the needed empty-width flags in the top bits for use later. State* state = CachedState(inst, n, flag); // Looks in the State cache for a State matching inst, ninst, flag. // Look in the cache for a pre-existing state. StateSet::iterator it = state_cache_.find(&state); // Must have enough memory for new state. // Allocate new state along with room for next_ and inst_. // Put state in cache and return it. // Clear the cache. Must hold cache_mutex_.w or be in destructor. // Copies insts in state s to the work queue q. // Adds ip to the work queue, following empty arrows according to flag. // Use astack_ to hold our stack of instructions yet to process. stk[nstk++] = id; Loop:
} // Running of work queues. In the work queue, order matters: // Runs the work queue, processing the empty strings indicated by flag. // Runs the work queue, processing the single byte c followed by any empty newq->clear();
} if (DebugDFA) // Processes input byte c in state, returning new state. // Processes input byte c in state, returning new state. // If someone else already computed this, return it. // Convert state into Workq. // Flags marking the kinds of empty-width things (^ $ etc) if (c == '\n') { if (c == kByteEndText) { // The state flag kFlagLastWord says whether the last // Okay, finally ready to run. // Most of the time, we build the state from the output of // Save afterflag along with ismatch and isword in new state. ns = WorkqToCachedState(q0_, flag); // Flush ns before linking to it. ////////////////////////////////////////////////////////////////////// // Reader-writer lock helper. class DFA::RWLocker { // If the lock is only held for reading right now, // Returns whether the lock is already held for writing. private: DISALLOW_COPY_AND_ASSIGN(RWLocker); DFA::RWLocker::RWLocker(Mutex* mu) mu_->ReaderLock(); // This function is marked as NO_THREAD_SAFETY_ANALYSIS because the annotations |
Thank you for investigating! Just to confirm, the initialisation change was necessary to satisfy MSVC? |
On 7/4/2016 12:19 AM, Paul Wankadia wrote:
|
Okay, thanks! |
After the last commit, re2 builds with no errors and no warnings and all tests pass. |
3>E:\src\re2\re2\dfa.cc(104): warning C4200: nonstandard extension used: zero-sized array in struct/union
3> E:\src\re2\re2\dfa.cc(104): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
3>E:\src\re2\re2\dfa.cc(729): error C2466: cannot allocate an array of constant size 0
3>E:\src\re2\re2\onepass.cc(134): warning C4200: nonstandard extension used: zero-sized array in struct/union
3> E:\src\re2\re2\onepass.cc(134): note: Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array
Setting the zero-size array to one compiles cleanly but may not be the desired way to handle this.
The text was updated successfully, but these errors were encountered: