diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-04-20 04:46:55 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-04-20 04:46:55 (GMT) |
commit | 24ea8d3d9c85d54bcc8c242a073c0886a0273c36 (patch) | |
tree | a1822b64abeaa084c2d26cd0066d577f0a941248 /Objects | |
parent | d9a10509ace3fc749d299bd5c117c745f72275d7 (diff) | |
download | cpython-24ea8d3d9c85d54bcc8c242a073c0886a0273c36.zip cpython-24ea8d3d9c85d54bcc8c242a073c0886a0273c36.tar.gz cpython-24ea8d3d9c85d54bcc8c242a073c0886a0273c36.tar.bz2 |
Fix SF bug #505315: Make free and cell vars show up consistently in locals().
PyFrame_FastToLocals() and PyFrame_LocalsToFast() had a return if
f_nlocals was 0. I think this was a holdover from the pre 2.1 days
when regular locals were the only kind of local variables.
The change makes it possible to use a free variable in eval or exec if
it the variable is also used elsewhere in the same block, which is
what the documentation says.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/frameobject.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 165121d..6adc036 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -416,8 +416,6 @@ PyFrame_FastToLocals(PyFrameObject *f) return; } } - if (f->f_nlocals == 0) - return; map = f->f_code->co_varnames; if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; @@ -426,7 +424,8 @@ PyFrame_FastToLocals(PyFrameObject *f) j = PyTuple_Size(map); if (j > f->f_nlocals) j = f->f_nlocals; - map_to_dict(map, j, locals, fast, 0); + if (f->f_nlocals) + map_to_dict(map, j, locals, fast, 0); if (f->f_ncells || f->f_nfreevars) { if (!(PyTuple_Check(f->f_code->co_cellvars) && PyTuple_Check(f->f_code->co_freevars))) { @@ -455,7 +454,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) return; locals = f->f_locals; map = f->f_code->co_varnames; - if (locals == NULL || f->f_code->co_nlocals == 0) + if (locals == NULL) return; if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; @@ -464,7 +463,8 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) j = PyTuple_Size(map); if (j > f->f_nlocals) j = f->f_nlocals; - dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); + if (f->f_nlocals) + dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); if (f->f_ncells || f->f_nfreevars) { if (!(PyTuple_Check(f->f_code->co_cellvars) && PyTuple_Check(f->f_code->co_freevars))) @@ -474,7 +474,8 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) locals, fast + f->f_nlocals, 1, clear); dict_to_map(f->f_code->co_freevars, PyTuple_GET_SIZE(f->f_code->co_freevars), - locals, fast + f->f_nlocals + f->f_ncells, 1, clear); + locals, fast + f->f_nlocals + f->f_ncells, 1, + clear); } PyErr_Restore(error_type, error_value, error_traceback); } |