mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-104619: never leak comprehension locals to outer locals() (#104637)
This commit is contained in:
parent
86e6f16ccb
commit
70c7796477
2 changed files with 32 additions and 21 deletions
|
@ -5490,31 +5490,29 @@ push_inlined_comprehension_state(struct compiler *c, location loc,
|
|||
}
|
||||
Py_DECREF(outv);
|
||||
}
|
||||
if (outsc == LOCAL || outsc == CELL || outsc == FREE) {
|
||||
// local names bound in comprehension must be isolated from
|
||||
// outer scope; push existing value (which may be NULL if
|
||||
// not defined) on stack
|
||||
// local names bound in comprehension must be isolated from
|
||||
// outer scope; push existing value (which may be NULL if
|
||||
// not defined) on stack
|
||||
if (state->pushed_locals == NULL) {
|
||||
state->pushed_locals = PyList_New(0);
|
||||
if (state->pushed_locals == NULL) {
|
||||
state->pushed_locals = PyList_New(0);
|
||||
if (state->pushed_locals == NULL) {
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
// in the case of a cell, this will actually push the cell
|
||||
// itself to the stack, then we'll create a new one for the
|
||||
// comprehension and restore the original one after
|
||||
ADDOP_NAME(c, loc, LOAD_FAST_AND_CLEAR, k, varnames);
|
||||
if (scope == CELL) {
|
||||
if (outsc == FREE) {
|
||||
ADDOP_NAME(c, loc, MAKE_CELL, k, freevars);
|
||||
} else {
|
||||
ADDOP_NAME(c, loc, MAKE_CELL, k, cellvars);
|
||||
}
|
||||
}
|
||||
if (PyList_Append(state->pushed_locals, k) < 0) {
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
// in the case of a cell, this will actually push the cell
|
||||
// itself to the stack, then we'll create a new one for the
|
||||
// comprehension and restore the original one after
|
||||
ADDOP_NAME(c, loc, LOAD_FAST_AND_CLEAR, k, varnames);
|
||||
if (scope == CELL) {
|
||||
if (outsc == FREE) {
|
||||
ADDOP_NAME(c, loc, MAKE_CELL, k, freevars);
|
||||
} else {
|
||||
ADDOP_NAME(c, loc, MAKE_CELL, k, cellvars);
|
||||
}
|
||||
}
|
||||
if (PyList_Append(state->pushed_locals, k) < 0) {
|
||||
return ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (state->pushed_locals) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue