[Python-checkins] python/dist/src/Python ast.c,1.1.2.25,1.1.2.26
nnorwitz@users.sourceforge.net
nnorwitz@users.sourceforge.net
Wed, 02 Apr 2003 16:51:47 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv24790/Python
Modified Files:
Tag: ast-branch
ast.c
Log Message:
Add lots of error checking on malloc failure
Remove unnecessary breaks/return which follow a return
Index: ast.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/ast.c,v
retrieving revision 1.1.2.25
retrieving revision 1.1.2.26
diff -C2 -d -r1.1.2.25 -r1.1.2.26
*** ast.c 2 Apr 2003 04:22:16 -0000 1.1.2.25
--- ast.c 3 Apr 2003 00:51:45 -0000 1.1.2.26
***************
*** 104,107 ****
--- 104,109 ----
fprintf(stderr, "file_input containing %d statements\n", total);
stmts = asdl_seq_new(total);
+ if (!stmts)
+ return NULL;
for (i = 0; i < NCH(n) - 1; i++) {
ch = CHILD(n, i);
***************
*** 129,133 ****
case eval_input:
return Expression(ast_for_testlist(CHILD(n, 0)));
- break;
case single_input:
if (TYPE(CHILD(n, 0)) == NEWLINE) {
--- 131,134 ----
***************
*** 337,342 ****
seq = asdl_seq_new((NCH(n) + 1) / 2);
! for (i = 0; i < NCH(n); i += 2) {
! asdl_seq_SET(seq, i / 2, ast_for_expr(CHILD(n, i)));
}
return seq;
--- 338,345 ----
seq = asdl_seq_new((NCH(n) + 1) / 2);
! if (seq) {
! for (i = 0; i < NCH(n); i += 2) {
! asdl_seq_SET(seq, i / 2, ast_for_expr(CHILD(n, i)));
! }
}
return seq;
***************
*** 377,381 ****
--- 380,390 ----
}
args = n_args ? asdl_seq_new(n_args) : NULL;
+ if (!args && n_args)
+ return NULL;
defaults = n_defaults? asdl_seq_new(n_defaults) : NULL;
+ if (!defaults && n_defaults) {
+ if (args) asdl_seq_free(args);
+ return NULL;
+ }
/* fpdef: NAME | '(' fplist ')'
***************
*** 389,392 ****
--- 398,405 ----
if (NCH(ch) == 3) {
/* XXX don't handle fplist yet */
+ if (args)
+ asdl_seq_free(args);
+ if (defaults)
+ asdl_seq_free(defaults);
return NULL;
}
***************
*** 508,511 ****
--- 521,528 ----
n_fors = count_list_fors(n);
listcomps = asdl_seq_new(n_fors);
+ if (!listcomps) {
+ /* XXX free elt? */
+ return NULL;
+ }
ch = CHILD(n, 1);
for (i = 0; i < n_fors; i++) {
***************
*** 526,529 ****
--- 543,551 ----
n_ifs = count_list_ifs(ch);
ifs = asdl_seq_new(n_ifs);
+ if (!ifs) {
+ /* XXX free elt? */
+ asdl_seq_free(listcomps);
+ return NULL;
+ }
for (j = 0; j < n_ifs; j++) {
REQ(ch, list_iter);
***************
*** 557,571 ****
/* All names start in Load context, but may later be changed. */
return Name(NEW_IDENTIFIER(ch), Load);
- break;
case STRING:
/* XXX parsestrplus can return NULL. */
return Str(parsestrplus(n));
- break;
case NUMBER:
return Num(parsenumber(STR(ch)));
- break;
case LPAR: /* some parenthesized expressions */
return ast_for_testlist(CHILD(n, 1));
- break;
case LSQB: /* list (or list comprehension) */
ch = CHILD(n, 1);
--- 579,589 ----
***************
*** 587,591 ****
--- 605,615 ----
size = (NCH(ch) + 1) / 4; /* plus one in case no trailing comma */
keys = asdl_seq_new(size);
+ if (!keys)
+ return NULL;
values = asdl_seq_new(size);
+ if (!values) {
+ asdl_seq_free(keys);
+ return NULL;
+ }
for (i = 0; i < NCH(ch); i += 4) {
asdl_seq_SET(keys, i / 4, ast_for_expr(CHILD(ch, i)));
***************
*** 593,601 ****
}
return Dict(keys, values);
- break;
}
case BACKQUOTE: /* repr */
return Repr(ast_for_testlist(CHILD(n, 1)));
- break;
default:
fprintf(stderr, "unhandled atom %d\n", TYPE(ch));
--- 617,623 ----
***************
*** 710,713 ****
--- 732,737 ----
}
seq = asdl_seq_new((NCH(n) + 1) / 2);
+ if (!seq)
+ return NULL;
for (i = 0; i < NCH(n); i += 2) {
expr_ty e = ast_for_expr(CHILD(n, i));
***************
*** 737,741 ****
--- 761,771 ----
asdl_seq *ops, *cmps;
ops = asdl_seq_new(NCH(n) / 2);
+ if (!ops)
+ return NULL;
cmps = asdl_seq_new(NCH(n) / 2);
+ if (!cmps) {
+ asdl_seq_free(ops);
+ return NULL;
+ }
for (i = 1; i < NCH(n); i += 2) {
/* XXX cmpop_ty is just an enum */
***************
*** 805,808 ****
--- 835,840 ----
int j;
asdl_seq *slices = asdl_seq_new(NCH(ch) / 2);
+ if (!slices)
+ return NULL;
for (j = 0; j < NCH(ch); j += 2)
asdl_seq_SET(slices, j / 2,
***************
*** 848,851 ****
--- 880,885 ----
args = asdl_seq_new(nargs);
+ if (!args)
+ return NULL;
for (i = 0; i < NCH(n); i++) {
node *ch = CHILD(n, i);
***************
*** 905,913 ****
REQ(CHILD(n, 1), EQUAL);
targets = asdl_seq_new(NCH(n) / 2);
for (i = 0; i < NCH(n) - 2; i += 2) {
expr_ty e = ast_for_testlist(CHILD(n, i));
/* set context to assign */
! if (!e)
! return NULL;
set_context(e, Store);
asdl_seq_SET(targets, i / 2, e);
--- 939,951 ----
REQ(CHILD(n, 1), EQUAL);
targets = asdl_seq_new(NCH(n) / 2);
+ if (!targets)
+ return NULL;
for (i = 0; i < NCH(n) - 2; i += 2) {
expr_ty e = ast_for_testlist(CHILD(n, i));
/* set context to assign */
! if (!e) {
! asdl_seq_free(targets);
! return NULL;
! }
set_context(e, Store);
asdl_seq_SET(targets, i / 2, e);
***************
*** 936,939 ****
--- 974,979 ----
}
seq = asdl_seq_new((NCH(n) + 1 - start) / 2);
+ if (!seq)
+ return NULL;
for (i = start; i < NCH(n); i += 2) {
asdl_seq_APPEND(seq, ast_for_expr(CHILD(n, i)));
***************
*** 954,961 ****
seq = asdl_seq_new((NCH(n) + 1) / 2);
for (i = 0; i < NCH(n); i += 2) {
e = ast_for_expr(CHILD(n, i));
! if (!e)
! return NULL;
if (context)
set_context(e, context);
--- 994,1005 ----
seq = asdl_seq_new((NCH(n) + 1) / 2);
+ if (!seq)
+ return NULL;
for (i = 0; i < NCH(n); i += 2) {
e = ast_for_expr(CHILD(n, i));
! if (!e) {
! asdl_seq_free(seq);
! return NULL;
! }
if (context)
set_context(e, context);
***************
*** 1100,1110 ****
if (STR(CHILD(n, 0))[0] == 'i') { /* import */
aliases = asdl_seq_new(NCH(n) / 2);
for (i = 1; i < NCH(n); i += 2)
asdl_seq_SET(aliases, i / 2, alias_for_import_name(CHILD(n, i)));
return Import(aliases, LINENO(n));
} else if (STR(CHILD(n, 0))[0] == 'f') { /* from */
- alias_ty mod = alias_for_import_name(CHILD(n, 1));
stmt_ty import;
aliases = asdl_seq_new((NCH(n) - 2) / 2);
for (i = 3; i <= NCH(n); i += 2)
asdl_seq_APPEND(aliases, alias_for_import_name(CHILD(n, i)));
--- 1144,1162 ----
if (STR(CHILD(n, 0))[0] == 'i') { /* import */
aliases = asdl_seq_new(NCH(n) / 2);
+ if (!aliases)
+ return NULL;
for (i = 1; i < NCH(n); i += 2)
asdl_seq_SET(aliases, i / 2, alias_for_import_name(CHILD(n, i)));
return Import(aliases, LINENO(n));
} else if (STR(CHILD(n, 0))[0] == 'f') { /* from */
stmt_ty import;
+ alias_ty mod = alias_for_import_name(CHILD(n, 1));
+ if (!mod)
+ return NULL;
aliases = asdl_seq_new((NCH(n) - 2) / 2);
+ if (!aliases) {
+ free(mod);
+ return NULL;
+ }
for (i = 3; i <= NCH(n); i += 2)
asdl_seq_APPEND(aliases, alias_for_import_name(CHILD(n, i)));
***************
*** 1126,1133 ****
REQ(n, global_stmt);
s = asdl_seq_new(NCH(n) / 2);
for (i = 1; i < NCH(n); i += 2) {
name = NEW_IDENTIFIER(CHILD(n, i));
! if (!name)
return NULL;
asdl_seq_SET(s, i / 2, name);
}
--- 1178,1189 ----
REQ(n, global_stmt);
s = asdl_seq_new(NCH(n) / 2);
+ if (!s)
+ return NULL;
for (i = 1; i < NCH(n); i += 2) {
name = NEW_IDENTIFIER(CHILD(n, i));
! if (!name) {
! asdl_seq_free(s);
return NULL;
+ }
asdl_seq_SET(s, i / 2, name);
}
***************
*** 1179,1182 ****
--- 1235,1240 ----
total = num_stmts(n);
seq = asdl_seq_new(total);
+ if (!seq)
+ return NULL;
if (TYPE(CHILD(n, 0)) == simple_stmt) {
n = CHILD(n, 0);
***************
*** 1257,1260 ****
--- 1315,1320 ----
if (has_else) {
orelse = asdl_seq_new(1);
+ if (!orelse)
+ return NULL;
asdl_seq_SET(orelse, 0,
If(ast_for_expr(CHILD(n, NCH(n) - 6)),
***************
*** 1270,1273 ****
--- 1330,1335 ----
int off = 5 + (n_elif - i - 1) * 4;
asdl_seq *new = asdl_seq_new(1);
+ if (!new)
+ return NULL;
asdl_seq_SET(new, 0,
If(ast_for_expr(CHILD(n, off)),
***************
*** 1369,1372 ****
--- 1431,1436 ----
n_except /= 3;
handlers = asdl_seq_new(n_except);
+ if (!handlers)
+ return NULL;
for (i = 0; i < n_except; i++)
asdl_seq_SET(handlers, i,
***************
*** 1396,1404 ****
else {
bases = asdl_seq_new(1);
asdl_seq_SET(bases, 0, _bases);
}
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases,
ast_for_suite(CHILD(n, 6)), LINENO(n));
- return NULL;
}
--- 1460,1469 ----
else {
bases = asdl_seq_new(1);
+ if (!bases)
+ return NULL;
asdl_seq_SET(bases, 0, _bases);
}
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases,
ast_for_suite(CHILD(n, 6)), LINENO(n));
}