]> granicus.if.org Git - re2c/commitdiff
- Change CharSet to use heap instead of stack
authorhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Tue, 3 Jan 2006 11:40:38 +0000 (11:40 +0000)
committerhelly <helly@642ea486-5414-0410-9d7f-a0204ed87703>
Tue, 3 Jan 2006 11:40:38 +0000 (11:40 +0000)
# Stack causes SEGVs for larger .re's
# Maybe it is even better to switch to std::map

actions.cc
ins.h
re.h

index 3356dd56409c22e71e250941bdfb962d5df5fbd4..9b15cd9bc791255cf895f50c112b2e5e44fce8f1 100644 (file)
@@ -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 14b11feb2e6b20771b3b35bb098523ecd9383dd0..d0aabb1d0be4da948d8cec55b0eb92ebec9db4d7 100644 (file)
--- 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 089f1ea20149874ff0e99e9a545bec0a683a6061..b817a086d634bf67b7de9b4ec8ab0f664e9cb5d1 100644 (file)
--- a/re.h
+++ b/re.h
@@ -5,6 +5,7 @@
 #include <iostream>
 #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