Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-126366: Fix crash if __iter__ raises an exception during yield from #126369

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

Merged
merged 5 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 13 Lib/test/test_yield_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,19 @@ def outer():
self.assertIsNone(caught.exception.__context__)
self.assert_stop_iteration(g)

def test_throws_in_iter(self):
# See GH-126366: NULL pointer dereference if __iter__
# threw an exception.
class Silly:
def __iter__(self):
raise RuntimeError("nobody expects the spanish inquisition")

def my_generator():
yield from Silly()

with self.assertRaisesRegex(RuntimeError, "nobody expects the spanish inquisition"):
next(iter(my_generator()))


if __name__ == '__main__':
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix crash when using ``yield from`` on an object that raises an exception in
its ``__iter__``.
5 changes: 3 additions & 2 deletions 5 Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2791,11 +2791,12 @@ dummy_func(
}
else {
/* `iterable` is not a generator. */
iter = PyStackRef_FromPyObjectSteal(PyObject_GetIter(iterable_o));
PyObject *iter_o = PyObject_GetIter(iterable_o);
DEAD(iterable);
if (PyStackRef_IsNull(iter)) {
if (iter_o == NULL) {
ERROR_NO_POP();
}
iter = PyStackRef_FromPyObjectSteal(iter_o);
DECREF_INPUTS();
}
}
Expand Down
5 changes: 3 additions & 2 deletions 5 Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions 5 Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions 1 Tools/jit/ignore-tests-emulated-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ test.test_subprocess.ProcessTestCaseNoPoll.test_empty_env
test.test_subprocess.ProcessTestCaseNoPoll.test_file_not_found_includes_filename
test.test_subprocess.ProcessTestCaseNoPoll.test_one_environment_variable
test.test_venv.BasicTest.test_zippath_from_non_installed_posix
test.test_subprocess.POSIXProcessTestCase.test_vfork_used_when_expected
ZeroIntensity marked this conversation as resolved.
Show resolved Hide resolved
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.