diff options
author | Benjamin Peterson <benjamin@python.org> | 2008-11-25 04:00:37 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2008-11-25 04:00:37 (GMT) |
commit | 5cb6763dfd0818bf41c8f969cbf8b8b36666f72e (patch) | |
tree | 786104d65259d99a359e630dd62600705218dc31 /Python/ast.c | |
parent | 9e233a545c681118f453d2300b4af2317273dfaa (diff) | |
download | cpython-5cb6763dfd0818bf41c8f969cbf8b8b36666f72e.zip cpython-5cb6763dfd0818bf41c8f969cbf8b8b36666f72e.tar.gz cpython-5cb6763dfd0818bf41c8f969cbf8b8b36666f72e.tar.bz2 |
Merged revisions 67373 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67373 | benjamin.peterson | 2008-11-24 21:43:14 -0600 (Mon, 24 Nov 2008) | 2 lines
always check the return value of NEW_IDENTIFIER
........
Diffstat (limited to 'Python/ast.c')
-rw-r--r-- | Python/ast.c | 79 |
1 files changed, 59 insertions, 20 deletions
diff --git a/Python/ast.c b/Python/ast.c index 9673cec..9d09dfc 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -47,7 +47,8 @@ static PyObject *parsestrplus(struct compiling *, const node *n); static identifier new_identifier(const char* n, PyArena *arena) { PyObject* id = PyString_InternFromString(n); - PyArena_AddPyObject(arena, id); + if (id != NULL) + PyArena_AddPyObject(arena, id); return id; } @@ -597,6 +598,7 @@ compiler_complex_args(struct compiling *c, const node *n) */ REQ(n, fplist); for (i = 0; i < len; i++) { + PyObject *arg_id; const node *fpdef_node = CHILD(n, 2*i); const node *child; expr_ty arg; @@ -605,9 +607,12 @@ set_name: child = CHILD(fpdef_node, 0); if (TYPE(child) == NAME) { if (!forbidden_check(c, n, STR(child))) - return NULL; - arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child), - child->n_col_offset, c->c_arena); + return NULL; + arg_id = NEW_IDENTIFIER(child); + if (!arg_id) + return NULL; + arg = Name(arg_id, Store, LINENO(child), child->n_col_offset, + c->c_arena); } else { assert(TYPE(fpdef_node) == fpdef); @@ -717,11 +722,14 @@ ast_for_arguments(struct compiling *c, const node *n) } } if (TYPE(CHILD(ch, 0)) == NAME) { + PyObject *id; expr_ty name; if (!forbidden_check(c, n, STR(CHILD(ch, 0)))) goto error; - name = Name(NEW_IDENTIFIER(CHILD(ch, 0)), - Param, LINENO(ch), ch->n_col_offset, + id = NEW_IDENTIFIER(CHILD(ch, 0)); + if (!id) + goto error; + name = Name(id, Param, LINENO(ch), ch->n_col_offset, c->c_arena); if (!name) goto error; @@ -734,12 +742,16 @@ ast_for_arguments(struct compiling *c, const node *n) if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1)))) goto error; vararg = NEW_IDENTIFIER(CHILD(n, i+1)); + if (!vararg) + goto error; i += 3; break; case DOUBLESTAR: if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1)))) goto error; kwarg = NEW_IDENTIFIER(CHILD(n, i+1)); + if (!kwarg) + goto error; i += 3; break; default: @@ -1275,11 +1287,14 @@ ast_for_atom(struct compiling *c, const node *n) node *ch = CHILD(n, 0); switch (TYPE(ch)) { - case NAME: + case NAME: { /* All names start in Load context, but may later be changed. */ - return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, - c->c_arena); + PyObject *name = NEW_IDENTIFIER(ch); + if (!name) + return NULL; + return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena); + } case STRING: { PyObject *str = parsestrplus(c, n); if (!str) { @@ -1537,7 +1552,10 @@ ast_for_trailer(struct compiling *c, const node *n, expr_ty left_expr) return ast_for_call(c, CHILD(n, 1), left_expr); } else if (TYPE(CHILD(n, 0)) == DOT ) { - return Attribute(left_expr, NEW_IDENTIFIER(CHILD(n, 1)), Load, + PyObject *attr_id = NEW_IDENTIFIER(CHILD(n, 1)); + if (!attr_id) + return NULL; + return Attribute(left_expr, attr_id, Load, LINENO(n), n->n_col_offset, c->c_arena); } else { @@ -2311,7 +2329,7 @@ alias_for_import_name(struct compiling *c, const node *n) dotted_as_name: dotted_name ['as' NAME] dotted_name: NAME ('.' NAME)* */ - PyObject *str; + PyObject *str, *name; loop: switch (TYPE(n)) { @@ -2319,8 +2337,13 @@ alias_for_import_name(struct compiling *c, const node *n) str = NULL; if (NCH(n) == 3) { str = NEW_IDENTIFIER(CHILD(n, 2)); + if (!str) + return NULL; } - return alias(NEW_IDENTIFIER(CHILD(n, 0)), str, c->c_arena); + name = NEW_IDENTIFIER(CHILD(n, 0)); + if (!name) + return NULL; + return alias(name, str, c->c_arena); case dotted_as_name: if (NCH(n) == 1) { n = CHILD(n, 0); @@ -2332,12 +2355,18 @@ alias_for_import_name(struct compiling *c, const node *n) return NULL; assert(!a->asname); a->asname = NEW_IDENTIFIER(CHILD(n, 2)); + if (!a->asname) + return NULL; return a; } break; case dotted_name: - if (NCH(n) == 1) - return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena); + if (NCH(n) == 1) { + name = NEW_IDENTIFIER(CHILD(n, 0)); + if (!name) + return NULL; + return alias(name, NULL, c->c_arena); + } else { /* Create a string of the form "a.b.c" */ int i; @@ -3016,6 +3045,7 @@ static stmt_ty ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) { /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ + PyObject *classname; asdl_seq *bases, *s; REQ(n, classdef); @@ -3027,16 +3057,22 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) s = ast_for_suite(c, CHILD(n, 3)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, c->c_arena); + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; + return ClassDef(classname, NULL, s, decorator_seq, LINENO(n), + n->n_col_offset, c->c_arena); } /* check for empty base list */ if (TYPE(CHILD(n,3)) == RPAR) { s = ast_for_suite(c, CHILD(n,5)); if (!s) - return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, decorator_seq, - LINENO(n), n->n_col_offset, c->c_arena); + return NULL; + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; + return ClassDef(classname, NULL, s, decorator_seq, LINENO(n), + n->n_col_offset, c->c_arena); } /* else handle the base class list */ @@ -3047,7 +3083,10 @@ ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) s = ast_for_suite(c, CHILD(n, 6)); if (!s) return NULL; - return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), bases, s, decorator_seq, + classname = NEW_IDENTIFIER(CHILD(n, 1)); + if (!classname) + return NULL; + return ClassDef(classname, bases, s, decorator_seq, LINENO(n), n->n_col_offset, c->c_arena); } |