diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-06-13 16:19:19 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-06-13 16:19:19 (GMT) |
commit | 5d1ff94b9ef3052b4938c55b196c3594369e252a (patch) | |
tree | 02eec44492cc7d71a07d7296e2aabd0f8d72bd7e /Python | |
parent | 0805b28fd29be83b4fde3585dfb70634d33c52ca (diff) | |
download | cpython-5d1ff94b9ef3052b4938c55b196c3594369e252a.zip cpython-5d1ff94b9ef3052b4938c55b196c3594369e252a.tar.gz cpython-5d1ff94b9ef3052b4938c55b196c3594369e252a.tar.bz2 |
set Print.values to NULL if there are no values
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Python/ast.c b/Python/ast.c index d259259..a415495 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -2144,9 +2144,9 @@ ast_for_print_stmt(struct compiling *c, const node *n) | '>>' test [ (',' test)+ [','] ] ) */ expr_ty dest = NULL, expression; - asdl_seq *seq; + asdl_seq *seq = NULL; bool nl; - int i, j, start = 1; + int i, j, values_count, start = 1; REQ(n, print_stmt); if (NCH(n) >= 2 && TYPE(CHILD(n, 1)) == RIGHTSHIFT) { @@ -2155,14 +2155,17 @@ ast_for_print_stmt(struct compiling *c, const node *n) return NULL; start = 4; } - seq = asdl_seq_new((NCH(n) + 1 - start) / 2, c->c_arena); - if (!seq) - return NULL; - for (i = start, j = 0; i < NCH(n); i += 2, ++j) { - expression = ast_for_expr(c, CHILD(n, i)); - if (!expression) + values_count = (NCH(n) + 1 - start) / 2; + if (values_count) { + seq = asdl_seq_new(values_count, c->c_arena); + if (!seq) return NULL; - asdl_seq_SET(seq, j, expression); + for (i = start, j = 0; i < NCH(n); i += 2, ++j) { + expression = ast_for_expr(c, CHILD(n, i)); + if (!expression) + return NULL; + asdl_seq_SET(seq, j, expression); + } } nl = (TYPE(CHILD(n, NCH(n) - 1)) == COMMA) ? false : true; return Print(dest, seq, nl, LINENO(n), n->n_col_offset, c->c_arena); |