Set parse tree in parser data structure to NULL when returning

a valid parse tree to caller, so caller must free the tree.
This commit is contained in:
Guido van Rossum 1990-11-18 17:39:41 +00:00
parent 99f02d43f3
commit 840bcf11a8
1 changed files with 4 additions and 3 deletions

View File

@ -53,8 +53,10 @@ parsetok(tok, g, start, n_ret)
str[len] = '\0';
ret = addtoken(ps, (int)type, str);
if (ret != E_OK) {
if (ret == E_DONE)
if (ret == E_DONE) {
*n_ret = ps->p_tree;
ps->p_tree = NULL;
}
else if (tok->lineno <= 1 && tok->done == E_EOF)
ret = E_EOF;
break;
@ -112,8 +114,7 @@ parsefile(fp, g, start, ps1, ps2, n_ret)
ret = parsetok(tok, g, start, n_ret);
if (ret == E_TOKEN || ret == E_SYNTAX) {
char *p;
fprintf(stderr, "Parsing error at line %d:\n",
tok->lineno);
fprintf(stderr, "Parsing error at line %d:\n", tok->lineno);
*tok->inp = '\0';
if (tok->inp > tok->buf && tok->inp[-1] == '\n')
tok->inp[-1] = '\0';