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
........
This commit is contained in:
Benjamin Peterson 2008-11-25 04:00:37 +00:00
parent 9e233a545c
commit 5cb6763dfd
1 changed files with 59 additions and 20 deletions

View File

@ -47,7 +47,8 @@ static PyObject *parsestrplus(struct compiling *, const node *n);
static identifier static identifier
new_identifier(const char* n, PyArena *arena) { new_identifier(const char* n, PyArena *arena) {
PyObject* id = PyString_InternFromString(n); PyObject* id = PyString_InternFromString(n);
PyArena_AddPyObject(arena, id); if (id != NULL)
PyArena_AddPyObject(arena, id);
return id; return id;
} }
@ -597,6 +598,7 @@ compiler_complex_args(struct compiling *c, const node *n)
*/ */
REQ(n, fplist); REQ(n, fplist);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
PyObject *arg_id;
const node *fpdef_node = CHILD(n, 2*i); const node *fpdef_node = CHILD(n, 2*i);
const node *child; const node *child;
expr_ty arg; expr_ty arg;
@ -606,8 +608,11 @@ set_name:
if (TYPE(child) == NAME) { if (TYPE(child) == NAME) {
if (!forbidden_check(c, n, STR(child))) if (!forbidden_check(c, n, STR(child)))
return NULL; return NULL;
arg = Name(NEW_IDENTIFIER(child), Store, LINENO(child), arg_id = NEW_IDENTIFIER(child);
child->n_col_offset, c->c_arena); if (!arg_id)
return NULL;
arg = Name(arg_id, Store, LINENO(child), child->n_col_offset,
c->c_arena);
} }
else { else {
assert(TYPE(fpdef_node) == fpdef); assert(TYPE(fpdef_node) == fpdef);
@ -717,11 +722,14 @@ ast_for_arguments(struct compiling *c, const node *n)
} }
} }
if (TYPE(CHILD(ch, 0)) == NAME) { if (TYPE(CHILD(ch, 0)) == NAME) {
PyObject *id;
expr_ty name; expr_ty name;
if (!forbidden_check(c, n, STR(CHILD(ch, 0)))) if (!forbidden_check(c, n, STR(CHILD(ch, 0))))
goto error; goto error;
name = Name(NEW_IDENTIFIER(CHILD(ch, 0)), id = NEW_IDENTIFIER(CHILD(ch, 0));
Param, LINENO(ch), ch->n_col_offset, if (!id)
goto error;
name = Name(id, Param, LINENO(ch), ch->n_col_offset,
c->c_arena); c->c_arena);
if (!name) if (!name)
goto error; 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)))) if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))
goto error; goto error;
vararg = NEW_IDENTIFIER(CHILD(n, i+1)); vararg = NEW_IDENTIFIER(CHILD(n, i+1));
if (!vararg)
goto error;
i += 3; i += 3;
break; break;
case DOUBLESTAR: case DOUBLESTAR:
if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1)))) if (!forbidden_check(c, CHILD(n, i+1), STR(CHILD(n, i+1))))
goto error; goto error;
kwarg = NEW_IDENTIFIER(CHILD(n, i+1)); kwarg = NEW_IDENTIFIER(CHILD(n, i+1));
if (!kwarg)
goto error;
i += 3; i += 3;
break; break;
default: default:
@ -1275,11 +1287,14 @@ ast_for_atom(struct compiling *c, const node *n)
node *ch = CHILD(n, 0); node *ch = CHILD(n, 0);
switch (TYPE(ch)) { switch (TYPE(ch)) {
case NAME: case NAME: {
/* All names start in Load context, but may later be /* All names start in Load context, but may later be
changed. */ changed. */
return Name(NEW_IDENTIFIER(ch), Load, LINENO(n), n->n_col_offset, PyObject *name = NEW_IDENTIFIER(ch);
c->c_arena); if (!name)
return NULL;
return Name(name, Load, LINENO(n), n->n_col_offset, c->c_arena);
}
case STRING: { case STRING: {
PyObject *str = parsestrplus(c, n); PyObject *str = parsestrplus(c, n);
if (!str) { 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); return ast_for_call(c, CHILD(n, 1), left_expr);
} }
else if (TYPE(CHILD(n, 0)) == DOT ) { 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); LINENO(n), n->n_col_offset, c->c_arena);
} }
else { else {
@ -2311,7 +2329,7 @@ alias_for_import_name(struct compiling *c, const node *n)
dotted_as_name: dotted_name ['as' NAME] dotted_as_name: dotted_name ['as' NAME]
dotted_name: NAME ('.' NAME)* dotted_name: NAME ('.' NAME)*
*/ */
PyObject *str; PyObject *str, *name;
loop: loop:
switch (TYPE(n)) { switch (TYPE(n)) {
@ -2319,8 +2337,13 @@ alias_for_import_name(struct compiling *c, const node *n)
str = NULL; str = NULL;
if (NCH(n) == 3) { if (NCH(n) == 3) {
str = NEW_IDENTIFIER(CHILD(n, 2)); 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: case dotted_as_name:
if (NCH(n) == 1) { if (NCH(n) == 1) {
n = CHILD(n, 0); n = CHILD(n, 0);
@ -2332,12 +2355,18 @@ alias_for_import_name(struct compiling *c, const node *n)
return NULL; return NULL;
assert(!a->asname); assert(!a->asname);
a->asname = NEW_IDENTIFIER(CHILD(n, 2)); a->asname = NEW_IDENTIFIER(CHILD(n, 2));
if (!a->asname)
return NULL;
return a; return a;
} }
break; break;
case dotted_name: case dotted_name:
if (NCH(n) == 1) if (NCH(n) == 1) {
return alias(NEW_IDENTIFIER(CHILD(n, 0)), NULL, c->c_arena); name = NEW_IDENTIFIER(CHILD(n, 0));
if (!name)
return NULL;
return alias(name, NULL, c->c_arena);
}
else { else {
/* Create a string of the form "a.b.c" */ /* Create a string of the form "a.b.c" */
int i; int i;
@ -3016,6 +3045,7 @@ static stmt_ty
ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq) ast_for_classdef(struct compiling *c, const node *n, asdl_seq *decorator_seq)
{ {
/* classdef: 'class' NAME ['(' testlist ')'] ':' suite */ /* classdef: 'class' NAME ['(' testlist ')'] ':' suite */
PyObject *classname;
asdl_seq *bases, *s; asdl_seq *bases, *s;
REQ(n, classdef); 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)); s = ast_for_suite(c, CHILD(n, 3));
if (!s) if (!s)
return NULL; return NULL;
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, decorator_seq, classname = NEW_IDENTIFIER(CHILD(n, 1));
LINENO(n), n->n_col_offset, c->c_arena); 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 */ /* check for empty base list */
if (TYPE(CHILD(n,3)) == RPAR) { if (TYPE(CHILD(n,3)) == RPAR) {
s = ast_for_suite(c, CHILD(n,5)); s = ast_for_suite(c, CHILD(n,5));
if (!s) if (!s)
return NULL; return NULL;
return ClassDef(NEW_IDENTIFIER(CHILD(n, 1)), NULL, s, decorator_seq, classname = NEW_IDENTIFIER(CHILD(n, 1));
LINENO(n), n->n_col_offset, c->c_arena); 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 */ /* 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)); s = ast_for_suite(c, CHILD(n, 6));
if (!s) if (!s)
return NULL; 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); LINENO(n), n->n_col_offset, c->c_arena);
} }