[Python-checkins] commit of r41627 - python/branches/ast-arena/Python/ast.c
neal.norwitz
python-checkins at python.org
Tue Dec 6 08:42:45 CET 2005
Author: neal.norwitz
Date: Tue Dec 6 08:42:44 2005
New Revision: 41627
Modified:
python/branches/ast-arena/Python/ast.c
Log:
Get rid of unnecessary goto error labels. They can simply be return NULL;
Fix a few ref leaks wrt import a.b.c and from ... import *
Modified: python/branches/ast-arena/Python/ast.c
==============================================================================
--- python/branches/ast-arena/Python/ast.c (original)
+++ python/branches/ast-arena/Python/ast.c Tue Dec 6 08:42:44 2005
@@ -674,27 +674,24 @@
id = NEW_IDENTIFIER(CHILD(n, 0));
if (!id)
- goto error;
+ return NULL;
e = Name(id, Load, LINENO(n), c->c_arena);
if (!e)
- goto error;
+ return NULL;
id = NULL;
for (i = 2; i < NCH(n); i+=2) {
id = NEW_IDENTIFIER(CHILD(n, i));
if (!id)
- goto error;
+ return NULL;
attrib = Attribute(e, id, Load, LINENO(CHILD(n, i)), c->c_arena);
if (!attrib)
- goto error;
+ return NULL;
e = attrib;
attrib = NULL;
}
return e;
-
- error:
- return NULL;
}
static expr_ty
@@ -709,12 +706,12 @@
if ((NCH(n) < 3 && NCH(n) != 5 && NCH(n) != 6)
|| TYPE(CHILD(n, 0)) != AT || TYPE(RCHILD(n, -1)) != NEWLINE) {
ast_error(n, "Invalid decorator node");
- goto error;
+ return NULL;
}
name_expr = ast_for_dotted_name(c, CHILD(n, 1));
if (!name_expr)
- goto error;
+ return NULL;
if (NCH(n) == 3) { /* No arguments */
d = name_expr;
@@ -723,20 +720,17 @@
else if (NCH(n) == 5) { /* Call with no arguments */
d = Call(name_expr, NULL, NULL, NULL, NULL, LINENO(n), c->c_arena);
if (!d)
- goto error;
+ return NULL;
name_expr = NULL;
}
else {
d = ast_for_call(c, CHILD(n, 3), name_expr);
if (!d)
- goto error;
+ return NULL;
name_expr = NULL;
}
return d;
-
- error:
- return NULL;
}
static asdl_seq*
@@ -755,12 +749,10 @@
for (i = 0; i < NCH(n); i++) {
d = ast_for_decorator(c, CHILD(n, i));
if (!d)
- goto error;
+ return NULL;
asdl_seq_APPEND(decorator_seq, d);
}
return decorator_seq;
- error:
- return NULL;
}
static stmt_ty
@@ -778,7 +770,7 @@
if (NCH(n) == 6) { /* decorators are present */
decorator_seq = ast_for_decorators(c, CHILD(n, 0));
if (!decorator_seq)
- goto error;
+ return NULL;
name_i = 2;
}
else {
@@ -787,22 +779,19 @@
name = NEW_IDENTIFIER(CHILD(n, name_i));
if (!name)
- goto error;
+ return NULL;
else if (!strcmp(STR(CHILD(n, name_i)), "None")) {
ast_error(CHILD(n, name_i), "assignment to None");
- goto error;
+ return NULL;
}
args = ast_for_arguments(c, CHILD(n, name_i + 1));
if (!args)
- goto error;
+ return NULL;
body = ast_for_suite(c, CHILD(n, name_i + 3));
if (!body)
- goto error;
+ return NULL;
return FunctionDef(name, args, body, decorator_seq, LINENO(n), c->c_arena);
-
-error:
- return NULL;
}
static expr_ty
@@ -1673,10 +1662,10 @@
args = asdl_seq_new(nargs + ngens, c->c_arena);
if (!args)
- goto error;
+ return NULL;
keywords = asdl_seq_new(nkeywords, c->c_arena);
if (!keywords)
- goto error;
+ return NULL;
nargs = 0;
nkeywords = 0;
for (i = 0; i < NCH(n); i++) {
@@ -1686,13 +1675,13 @@
if (NCH(ch) == 1) {
e = ast_for_expr(c, CHILD(ch, 0));
if (!e)
- goto error;
+ return NULL;
asdl_seq_SET(args, nargs++, e);
}
else if (TYPE(CHILD(ch, 1)) == gen_for) {
e = ast_for_genexp(c, ch);
if (!e)
- goto error;
+ return NULL;
asdl_seq_SET(args, nargs++, e);
}
else {
@@ -1702,7 +1691,7 @@
/* CHILD(ch, 0) is test, but must be an identifier? */
e = ast_for_expr(c, CHILD(ch, 0));
if (!e)
- goto error;
+ return NULL;
/* f(lambda x: x[0] = 3) ends up getting parsed with
* LHS test = lambda x: x[0], and RHS test = 3.
* SF bug 132313 points out that complaining about a keyword
@@ -1710,18 +1699,18 @@
*/
if (e->kind == Lambda_kind) {
ast_error(CHILD(ch, 0), "lambda cannot contain assignment");
- goto error;
+ return NULL;
} else if (e->kind != Name_kind) {
ast_error(CHILD(ch, 0), "keyword can't be an expression");
- goto error;
+ return NULL;
}
key = e->v.Name.id;
e = ast_for_expr(c, CHILD(ch, 2));
if (!e)
- goto error;
+ return NULL;
kw = keyword(key, e, c->c_arena);
if (!kw)
- goto error;
+ return NULL;
asdl_seq_SET(keywords, nkeywords++, kw);
}
}
@@ -1736,9 +1725,6 @@
}
return Call(func, args, keywords, vararg, kwarg, LINENO(n), c->c_arena);
-
- error:
- return NULL;
}
static expr_ty
@@ -1882,16 +1868,16 @@
node *ch = CHILD(n, i);
if (TYPE(ch) == yield_expr) {
ast_error(ch, "assignment to yield expression not possible");
- goto error;
+ return NULL;
}
e = ast_for_testlist(c, ch);
/* set context to assign */
if (!e)
- goto error;
+ return NULL;
if (!set_context(e, Store, CHILD(n, i))) {
- goto error;
+ return NULL;
}
asdl_seq_SET(targets, i / 2, e);
@@ -1902,12 +1888,9 @@
else
expression = ast_for_expr(c, value);
if (!expression)
- goto error;
+ return NULL;
return Assign(targets, expression, LINENO(n), c->c_arena);
- error:
- (void)1;
}
- return NULL;
}
static stmt_ty
@@ -1958,17 +1941,14 @@
for (i = 0; i < NCH(n); i += 2) {
e = ast_for_expr(c, CHILD(n, i));
if (!e)
- goto error;
+ return NULL;
asdl_seq_SET(seq, i / 2, e);
if (context) {
if (!set_context(e, context, CHILD(n, i)))
- goto error;
+ return NULL;
}
}
return seq;
-
-error:
- return NULL;
}
static stmt_ty
@@ -2073,6 +2053,8 @@
dotted_as_name: dotted_name [NAME NAME]
dotted_name: NAME ('.' NAME)*
*/
+ PyObject *str;
+
loop:
switch (TYPE(n)) {
case import_as_name:
@@ -2101,7 +2083,6 @@
else {
/* Create a string of the form "a.b.c" */
int i, len;
- PyObject *str;
char *s;
len = 0;
@@ -2124,11 +2105,14 @@
--s;
*s = '\0';
PyString_InternInPlace(&str);
+ PyArena_AddPyObject(c->c_arena, str);
return alias(str, NULL, c->c_arena);
}
break;
case STAR:
- return alias(PyString_InternFromString("*"), NULL, c->c_arena);
+ str = PyString_InternFromString("*");
+ PyArena_AddPyObject(c->c_arena, str);
+ return alias(str, NULL, c->c_arena);
default:
PyErr_Format(PyExc_SystemError,
"unexpected import name: %d", TYPE(n));
@@ -2168,7 +2152,6 @@
return Import(aliases, LINENO(n), c->c_arena);
}
else if (STR(CHILD(n, 0))[0] == 'f') { /* from */
- stmt_ty import;
int n_children;
const char *from_modules;
int lineno = LINENO(n);
@@ -2223,9 +2206,7 @@
}
asdl_seq_APPEND(aliases, import_alias);
}
- Py_INCREF(mod->name);
- import = ImportFrom(mod->name, aliases, lineno, c->c_arena);
- return import;
+ return ImportFrom(mod->name, aliases, lineno, c->c_arena);
}
PyErr_Format(PyExc_SystemError,
"unknown import statement: starts with command '%s'",
@@ -2343,7 +2324,7 @@
ch = CHILD(n, i);
s = ast_for_stmt(c, ch);
if (!s)
- goto error;
+ return NULL;
asdl_seq_SET(seq, pos++, s);
}
}
@@ -2356,7 +2337,7 @@
/* small_stmt or compound_stmt with only one child */
s = ast_for_stmt(c, ch);
if (!s)
- goto error;
+ return NULL;
asdl_seq_SET(seq, pos++, s);
}
else {
@@ -2366,7 +2347,7 @@
for (j = 0; j < NCH(ch); j += 2) {
s = ast_for_stmt(c, CHILD(ch, j));
if (!s)
- goto error;
+ return NULL;
asdl_seq_SET(seq, pos++, s);
}
}
@@ -2374,8 +2355,6 @@
}
assert(pos == seq->size);
return seq;
- error:
- return NULL;
}
static stmt_ty
More information about the Python-checkins
mailing list