From: helly Date: Tue, 3 Jan 2006 11:40:38 +0000 (+0000) Subject: - Change CharSet to use heap instead of stack X-Git-Tag: 0.13.6~508 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d21994ac11cc1096615415ea6fe06a916a15781f;p=re2c - Change CharSet to use heap instead of stack # Stack causes SEGVs for larger .re's # Maybe it is even better to switch to std::map --- diff --git a/actions.cc b/actions.cc index 3356dd56..9b15cd9b 100644 --- a/actions.cc +++ b/actions.cc @@ -960,7 +960,6 @@ void genCode(std::ostream& o, uint ind, RegExp *re) { CharSet *cs = new CharSet(); uint j; - memset(cs, 0, sizeof(CharSet)); for (j = 0; j < nRealChars; ++j) { @@ -969,18 +968,18 @@ void genCode(std::ostream& o, uint ind, RegExp *re) } cs->freeHead = &cs->ptn[1]; - *(cs->freeTail = &cs->ptn[nChars - 1].nxt) = NULL; - cs->ptn[0].card = nChars; + *(cs->freeTail = &cs->ptn[nRealChars - 1].nxt) = NULL; + cs->ptn[0].card = nRealChars; cs->ptn[0].nxt = NULL; re->split(*cs); /* for(uint k = 0; k < nChars;){ - for(j = k; ++k < nChars && cs->rep[k] == cs->rep[j];); + for(j = k; ++k < nRealChars && cs->rep[k] == cs->rep[j];); printSpan(cerr, j, k); cerr << "\t" << cs->rep[j] - &cs->ptn[0] << endl; } */ - Char rep[nChars]; + Char *rep = new Char[nRealChars]; for (j = 0; j < nRealChars; ++j) { @@ -1018,6 +1017,7 @@ void genCode(std::ostream& o, uint ind, RegExp *re) dfa->emit(o, ind); delete dfa; delete [] ins; + delete [] rep; delete cs; } diff --git a/ins.h b/ins.h index 14b11feb..d0aabb1d 100644 --- a/ins.h +++ b/ins.h @@ -7,7 +7,6 @@ namespace re2c { -const uint nChars = (1<<16); typedef unsigned short Char; const uint CHAR = 0; diff --git a/re.h b/re.h index 089f1ea2..b817a086 100644 --- a/re.h +++ b/re.h @@ -5,6 +5,7 @@ #include #include "token.h" #include "ins.h" +#include "globals.h" namespace re2c { @@ -25,12 +26,29 @@ struct CharPtn CharPtn *nxt; }; +typedef CharPtn *CharPtr; + struct CharSet { + CharSet() + : fix(0) + , freeHead(0) + , freeTail(0) + , rep(new CharPtr[nRealChars]) + , ptn(new CharPtn[nRealChars]) + { + } + + ~CharSet() + { + delete[] rep; + delete[] ptn; + } + CharPtn *fix; CharPtn *freeHead, **freeTail; - CharPtn *rep[nChars]; - CharPtn ptn[nChars]; + CharPtr *rep; + CharPtn *ptn; }; class Range