summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2005-11-16 12:46:55 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2005-11-16 12:46:55 (GMT)
commit944d3eb1546e38d4944db5f2f41f5560d55a5053 (patch)
tree2222cdb66e04414e965a7f7f2fa41467d06dd407 /Python/compile.c
parent99b2533539dbc98fe7e5b3ac95e71879afca1c2c (diff)
downloadcpython-944d3eb1546e38d4944db5f2f41f5560d55a5053.zip
cpython-944d3eb1546e38d4944db5f2f41f5560d55a5053.tar.gz
cpython-944d3eb1546e38d4944db5f2f41f5560d55a5053.tar.bz2
Correctly handle identifiers for anonymous scopes and align genexpr name with symtable.c
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 8329687..4da81c0 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -12,6 +12,11 @@
*
* Note that compiler_mod() suggests module, but the module ast type
* (mod_ty) has cases for expressions and interactive statements.
+ *
+ * CAUTION: The VISIT_* macros abort the current function when they encounter
+ * a problem. So don't invoke them when there is memory which needs to be
+ * released. Code blocks are OK, as the compiler structure takes care of
+ * releasing those.
*/
#include "Python.h"
@@ -1990,13 +1995,15 @@ static int
compiler_lambda(struct compiler *c, expr_ty e)
{
PyCodeObject *co;
- identifier name;
+ static identifier name;
arguments_ty args = e->v.Lambda.args;
assert(e->kind == Lambda_kind);
- name = PyString_InternFromString("<lambda>");
- if (!name)
- return 0;
+ if (!name) {
+ name = PyString_InternFromString("<lambda>");
+ if (!name)
+ return 0;
+ }
if (args->defaults)
VISIT_SEQ(c, expr, args->defaults);
@@ -2015,7 +2022,6 @@ compiler_lambda(struct compiler *c, expr_ty e)
return 0;
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
- Py_DECREF(name);
return 1;
}
@@ -3168,15 +3174,17 @@ compiler_genexp_generator(struct compiler *c,
static int
compiler_genexp(struct compiler *c, expr_ty e)
{
- PyObject *name;
+ static identifier name;
PyCodeObject *co;
expr_ty outermost_iter = ((comprehension_ty)
(asdl_seq_GET(e->v.GeneratorExp.generators,
0)))->iter;
- name = PyString_FromString("<generator expression>");
- if (!name)
- return 0;
+ if (!name) {
+ name = PyString_FromString("<genexpr>");
+ if (!name)
+ return 0;
+ }
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
return 0;
@@ -3191,8 +3199,6 @@ compiler_genexp(struct compiler *c, expr_ty e)
VISIT(c, expr, outermost_iter);
ADDOP(c, GET_ITER);
ADDOP_I(c, CALL_FUNCTION, 1);
- Py_DECREF(name);
- Py_DECREF(co);
return 1;
}