Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 944d3eb

Browse files
committed
Correctly handle identifiers for anonymous scopes and align genexpr name with symtable.c
1 parent 99b2533 commit 944d3eb

1 file changed

Lines changed: 17 additions & 11 deletions

File tree

Python/compile.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
*
1313
* Note that compiler_mod() suggests module, but the module ast type
1414
* (mod_ty) has cases for expressions and interactive statements.
15+
*
16+
* CAUTION: The VISIT_* macros abort the current function when they encounter
17+
* a problem. So don't invoke them when there is memory which needs to be
18+
* released. Code blocks are OK, as the compiler structure takes care of
19+
* releasing those.
1520
*/
1621

1722
#include "Python.h"
@@ -1990,13 +1995,15 @@ static int
19901995
compiler_lambda(struct compiler *c, expr_ty e)
19911996
{
19921997
PyCodeObject *co;
1993-
identifier name;
1998+
static identifier name;
19941999
arguments_ty args = e->v.Lambda.args;
19952000
assert(e->kind == Lambda_kind);
19962001

1997-
name = PyString_InternFromString("<lambda>");
1998-
if (!name)
1999-
return 0;
2002+
if (!name) {
2003+
name = PyString_InternFromString("<lambda>");
2004+
if (!name)
2005+
return 0;
2006+
}
20002007

20012008
if (args->defaults)
20022009
VISIT_SEQ(c, expr, args->defaults);
@@ -2015,7 +2022,6 @@ compiler_lambda(struct compiler *c, expr_ty e)
20152022
return 0;
20162023

20172024
compiler_make_closure(c, co, asdl_seq_LEN(args->defaults));
2018-
Py_DECREF(name);
20192025

20202026
return 1;
20212027
}
@@ -3168,15 +3174,17 @@ compiler_genexp_generator(struct compiler *c,
31683174
static int
31693175
compiler_genexp(struct compiler *c, expr_ty e)
31703176
{
3171-
PyObject *name;
3177+
static identifier name;
31723178
PyCodeObject *co;
31733179
expr_ty outermost_iter = ((comprehension_ty)
31743180
(asdl_seq_GET(e->v.GeneratorExp.generators,
31753181
0)))->iter;
31763182

3177-
name = PyString_FromString("<generator expression>");
3178-
if (!name)
3179-
return 0;
3183+
if (!name) {
3184+
name = PyString_FromString("<genexpr>");
3185+
if (!name)
3186+
return 0;
3187+
}
31803188

31813189
if (!compiler_enter_scope(c, name, (void *)e, e->lineno))
31823190
return 0;
@@ -3191,8 +3199,6 @@ compiler_genexp(struct compiler *c, expr_ty e)
31913199
VISIT(c, expr, outermost_iter);
31923200
ADDOP(c, GET_ITER);
31933201
ADDOP_I(c, CALL_FUNCTION, 1);
3194-
Py_DECREF(name);
3195-
Py_DECREF(co);
31963202

31973203
return 1;
31983204
}

0 commit comments

Comments
 (0)