-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
gh-125038: Crash after genexpr.gi_frame.f_locals manipulations is fixed #125178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3dd0feb
f54918c
9665d13
233f6b6
ca04eef
b94d5c4
385b389
7aa00b4
890b936
d75a476
f93e8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fix crash when iterating over a generator expression after direct changes on ``gi_frame.f_locals``. | ||
Tests on generator modifying through ``gi_frame.f_locals`` are added, | ||
both to genexpr generators and function generators. Patch by Mikhail Efimov. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2806,7 +2806,16 @@ dummy_func( | |
replaced op(_FOR_ITER, (iter -- iter, next)) { | ||
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */ | ||
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter); | ||
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o); | ||
PyTypeObject *type = Py_TYPE(iter_o); | ||
iternextfunc iternext = type->tp_iternext; | ||
if (iternext == NULL) { | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
"'for' requires an object with " | ||
"__iter__ method, got %.100s", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error is incorrect as it's looking for
|
||
type->tp_name); | ||
ERROR_NO_POP(); | ||
} | ||
PyObject *next_o = (*iternext)(iter_o); | ||
if (next_o == NULL) { | ||
if (_PyErr_Occurred(tstate)) { | ||
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration); | ||
|
@@ -2832,7 +2841,16 @@ dummy_func( | |
op(_FOR_ITER_TIER_TWO, (iter -- iter, next)) { | ||
/* before: [iter]; after: [iter, iter()] *or* [] (and jump over END_FOR.) */ | ||
PyObject *iter_o = PyStackRef_AsPyObjectBorrow(iter); | ||
PyObject *next_o = (*Py_TYPE(iter_o)->tp_iternext)(iter_o); | ||
PyTypeObject *type = Py_TYPE(iter_o); | ||
iternextfunc iternext = type->tp_iternext; | ||
if (iternext == NULL) { | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
"'for' requires an object with " | ||
"__iter__ method, got %.100s", | ||
type->tp_name); | ||
ERROR_NO_POP(); | ||
} | ||
PyObject *next_o = (*iternext)(iter_o); | ||
if (next_o == NULL) { | ||
if (_PyErr_Occurred(tstate)) { | ||
int matches = _PyErr_ExceptionMatches(tstate, PyExc_StopIteration); | ||
|
@@ -2856,7 +2874,16 @@ dummy_func( | |
_Py_CODEUNIT *target; | ||
_PyStackRef iter_stackref = TOP(); | ||
PyObject *iter = PyStackRef_AsPyObjectBorrow(iter_stackref); | ||
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter); | ||
PyTypeObject *type = Py_TYPE(iter); | ||
iternextfunc iternext = type->tp_iternext; | ||
if (iternext == NULL) { | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
"'for' requires an object with " | ||
"__iter__ method, got %.100s", | ||
type->tp_name); | ||
ERROR_NO_POP(); | ||
} | ||
PyObject *next = (*iternext)(iter); | ||
if (next != NULL) { | ||
PUSH(PyStackRef_FromPyObjectSteal(next)); | ||
target = next_instr; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.