summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorCarl Meyer <carl@oddbird.net>2023-09-07 14:56:43 (GMT)
committerGitHub <noreply@github.com>2023-09-07 14:56:43 (GMT)
commitf2584eade378910b9ea18072bb1dab3dd58e23bb (patch)
tree5e7a43ea324938f916109e766c3077754ca52c32 /Objects
parentb72251de930c8ec6893f1b3f6fdf1640cc17dfed (diff)
downloadcpython-f2584eade378910b9ea18072bb1dab3dd58e23bb.zip
cpython-f2584eade378910b9ea18072bb1dab3dd58e23bb.tar.gz
cpython-f2584eade378910b9ea18072bb1dab3dd58e23bb.tar.bz2
gh-108732: include comprehension locals in frame.f_locals (#109026)
Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Objects')
-rw-r--r--Objects/frameobject.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 7017cc6..53764a4 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -25,10 +25,16 @@ static PyMemberDef frame_memberlist[] = {
static PyObject *
frame_getlocals(PyFrameObject *f, void *closure)
{
- if (PyFrame_FastToLocalsWithError(f) < 0)
+ if (f == NULL) {
+ PyErr_BadInternalCall();
return NULL;
- PyObject *locals = f->f_frame->f_locals;
- return Py_NewRef(locals);
+ }
+ assert(!_PyFrame_IsIncomplete(f->f_frame));
+ PyObject *locals = _PyFrame_GetLocals(f->f_frame, 1);
+ if (locals) {
+ f->f_fast_as_locals = 1;
+ }
+ return locals;
}
int
@@ -1342,11 +1348,11 @@ PyFrame_GetVarString(PyFrameObject *frame, const char *name)
int
PyFrame_FastToLocalsWithError(PyFrameObject *f)
{
- assert(!_PyFrame_IsIncomplete(f->f_frame));
if (f == NULL) {
PyErr_BadInternalCall();
return -1;
}
+ assert(!_PyFrame_IsIncomplete(f->f_frame));
int err = _PyFrame_FastToLocalsWithError(f->f_frame);
if (err == 0) {
f->f_fast_as_locals = 1;