Kaydet (Commit) 588633da authored tarafından Guido van Rossum's avatar Guido van Rossum

Parser/tokenizer.c (tok_nextc): zap tok->buf after freeing;

rest: abort() -> fatal(); small things
üst 66cb311f
...@@ -48,6 +48,7 @@ newgrammar(start) ...@@ -48,6 +48,7 @@ newgrammar(start)
g->g_start = start; g->g_start = start;
g->g_ll.ll_nlabels = 0; g->g_ll.ll_nlabels = 0;
g->g_ll.ll_label = NULL; g->g_ll.ll_label = NULL;
g->g_accel = 0;
return g; return g;
} }
...@@ -84,6 +85,10 @@ addstate(d) ...@@ -84,6 +85,10 @@ addstate(d)
s = &d->d_state[d->d_nstates++]; s = &d->d_state[d->d_nstates++];
s->s_narcs = 0; s->s_narcs = 0;
s->s_arc = NULL; s->s_arc = NULL;
s->s_lower = 0;
s->s_upper = 0;
s->s_accel = NULL;
s->s_accept = 0;
return s - d->d_state; return s - d->d_state;
} }
...@@ -139,7 +144,6 @@ findlabel(ll, type, str) ...@@ -139,7 +144,6 @@ findlabel(ll, type, str)
char *str; char *str;
{ {
int i; int i;
label *lb;
for (i = 0; i < ll->ll_nlabels; i++) { for (i = 0; i < ll->ll_nlabels; i++) {
if (ll->ll_label[i].lb_type == type /*&& if (ll->ll_label[i].lb_type == type /*&&
...@@ -147,7 +151,8 @@ findlabel(ll, type, str) ...@@ -147,7 +151,8 @@ findlabel(ll, type, str)
return i; return i;
} }
fprintf(stderr, "Label %d/'%s' not found\n", type, str); fprintf(stderr, "Label %d/'%s' not found\n", type, str);
abort(); fatal("grammar.c:findlabel()");
/*NOTREACHED*/
} }
/* Forward */ /* Forward */
...@@ -158,8 +163,10 @@ translatelabels(g) ...@@ -158,8 +163,10 @@ translatelabels(g)
grammar *g; grammar *g;
{ {
int i; int i;
#ifdef DEBUG
printf("Translating labels ...\n"); printf("Translating labels ...\n");
#endif
/* Don't translate EMPTY */ /* Don't translate EMPTY */
for (i = EMPTY+1; i < g->g_ll.ll_nlabels; i++) for (i = EMPTY+1; i < g->g_ll.ll_nlabels; i++)
translabel(g, &g->g_ll.ll_label[i]); translabel(g, &g->g_ll.ll_label[i]);
......
...@@ -86,10 +86,8 @@ static void ...@@ -86,10 +86,8 @@ static void
s_pop(s) s_pop(s)
register stack *s; register stack *s;
{ {
if (s_empty(s)) { if (s_empty(s))
fprintf(stderr, "s_pop: parser stack underflow -- FATAL\n"); fatal("s_pop: parser stack underflow -- FATAL");
abort();
}
s->s_top++; s->s_top++;
} }
......
...@@ -162,7 +162,7 @@ static char REQNFMT[] = "metacompile: less than %d children\n"; ...@@ -162,7 +162,7 @@ static char REQNFMT[] = "metacompile: less than %d children\n";
#define REQN(i, count) \ #define REQN(i, count) \
if (i < count) { \ if (i < count) { \
fprintf(stderr, REQNFMT, count); \ fprintf(stderr, REQNFMT, count); \
abort(); \ fatal("REQN"); \
} else } else
#else #else
...@@ -390,7 +390,7 @@ dumpnfa(ll, nf) ...@@ -390,7 +390,7 @@ dumpnfa(ll, nf)
/* PART TWO -- CONSTRUCT DFA -- Algorithm 3.1 from [Aho&Ullman 77] */ /* PART TWO -- CONSTRUCT DFA -- Algorithm 3.1 from [Aho&Ullman 77] */
static int static void
addclosure(ss, nf, istate) addclosure(ss, nf, istate)
bitset ss; bitset ss;
nfa *nf; nfa *nf;
...@@ -628,7 +628,7 @@ simplify(xx_nstates, xx_state) ...@@ -628,7 +628,7 @@ simplify(xx_nstates, xx_state)
ss_state *xx_state; ss_state *xx_state;
{ {
int changes; int changes;
int i, j, k; int i, j;
do { do {
changes = 0; changes = 0;
......
...@@ -64,7 +64,6 @@ main(argc, argv) ...@@ -64,7 +64,6 @@ main(argc, argv)
char **argv; char **argv;
{ {
grammar *g; grammar *g;
node *n;
FILE *fp; FILE *fp;
char *filename; char *filename;
......
...@@ -209,6 +209,7 @@ tok_nextc(tok) ...@@ -209,6 +209,7 @@ tok_nextc(tok)
tok->lineno++; tok->lineno++;
if (buf == NULL) { if (buf == NULL) {
free(tok->buf); free(tok->buf);
tok->buf = NULL;
free(new); free(new);
tok->done = E_NOMEM; tok->done = E_NOMEM;
return EOF; return EOF;
...@@ -309,10 +310,8 @@ tok_backup(tok, c) ...@@ -309,10 +310,8 @@ tok_backup(tok, c)
register int c; register int c;
{ {
if (c != EOF) { if (c != EOF) {
if (--tok->cur < tok->buf) { if (--tok->cur < tok->buf)
fprintf(stderr, "tok_backup: begin of buffer\n"); fatal("tok_backup: begin of buffer");
abort();
}
if (*tok->cur != c) if (*tok->cur != c)
*tok->cur = c; *tok->cur = c;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment