struct dfa *d;
size_t nss = cnfa->nstates * 2;
int wordsper = (cnfa->nstates + UBITS - 1) / UBITS;
- struct smalldfa *smallwas = sml;
+ bool ismalloced = false;
assert(cnfa != NULL && cnfa->nstates != 0);
ERR(REG_ESPACE);
return NULL;
}
+ ismalloced = true;
}
d = &sml->dfa;
d->ssets = sml->ssets;
d->work = &d->statesarea[nss];
d->outsarea = sml->outsarea;
d->incarea = sml->incarea;
- d->cptsmalloced = 0;
- d->mallocarea = (smallwas == NULL) ? (char *) sml : NULL;
+ d->ismalloced = ismalloced;
+ d->arraysmalloced = false; /* not separately allocated, anyway */
}
else
{
sizeof(struct sset *));
d->incarea = (struct arcp *) MALLOC(nss * cnfa->ncolors *
sizeof(struct arcp));
- d->cptsmalloced = 1;
- d->mallocarea = (char *) d;
+ d->ismalloced = true;
+ d->arraysmalloced = true;
+ /* now freedfa() will behave sanely */
if (d->ssets == NULL || d->statesarea == NULL ||
d->outsarea == NULL || d->incarea == NULL)
{
static void
freedfa(struct dfa *d)
{
- if (d->cptsmalloced)
+ if (d->arraysmalloced)
{
if (d->ssets != NULL)
FREE(d->ssets);
FREE(d->incarea);
}
- if (d->mallocarea != NULL)
- FREE(d->mallocarea);
+ if (d->ismalloced)
+ FREE(d);
}
/*
chr *lastpost; /* location of last cache-flushed success */
chr *lastnopr; /* location of last cache-flushed NOPROGRESS */
struct sset *search; /* replacement-search-pointer memory */
- int cptsmalloced; /* were the areas individually malloced? */
- char *mallocarea; /* self, or master malloced area, or NULL */
+ bool ismalloced; /* should this struct dfa be freed? */
+ bool arraysmalloced; /* should its subsidiary arrays be freed? */
};
#define WORK 1 /* number of work bitvectors needed */
#define FEWCOLORS 15
struct smalldfa
{
- struct dfa dfa;
+ struct dfa dfa; /* must be first */
struct sset ssets[FEWSTATES * 2];
unsigned statesarea[FEWSTATES * 2 + WORK];
struct sset *outsarea[FEWSTATES * 2 * FEWCOLORS];