https://github.com/python/cpython/commit/3e43bb609fc0e61f9570f9963b68bbbefdc7cf8a commit: 3e43bb609fc0e61f9570f9963b68bbbefdc7cf8a branch: 3.15 author: Kirill Podoprigora <[email protected]> committer: Eclips4 <[email protected]> date: 2026-11-10T20:19:50Z summary:
[3.15] gh-159054: Check `basicblock_addop()` failure in `push_cold_blocks_to_end()` (GH-159057) (#161777) (cherry picked from commit e0d1ef25476875317be6e5ee74e1f254eeb49126) Co-authored-by: Pengyu <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst M Lib/test/test_compile.py M Python/flowgraph.c diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index ec5d32f6f0b1f2..92f67cbd311854 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -39,6 +39,27 @@ def test_no_ending_newline(self): def test_empty(self): compile("", "<test>", "exec") + @support.requires_subprocess() + @support.nomemtest + def test_push_cold_blocks_to_end_allocation_failure(self): + code = textwrap.dedent(""" + from test import support + + source = "async def f():\\n await x\\n" + for n in range(1, 1000): + with support.inject_memory_error_cm(n, n + 1): + try: + compile(source, "<test>", "exec") + except MemoryError: + continue + break + else: + raise AssertionError("compile() never succeeded") + if n == 1: + raise AssertionError("no MemoryError raised") + """) + script_helper.assert_python_ok('-c', code) + def test_other_newlines(self): compile("\r\n", "<test>", "exec") compile("\r", "<test>", "exec") diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst new file mode 100644 index 00000000000000..eaa01aa05435a7 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-10-09-18-27-12.gh-issue-159054.YUCTvG.rst @@ -0,0 +1,2 @@ +Fixed a crash when an allocation failure occurred while compiling code +containing cold blocks. diff --git a/Python/flowgraph.c b/Python/flowgraph.c index efa313b2b89adc..668346248cdb7e 100644 --- a/Python/flowgraph.c +++ b/Python/flowgraph.c @@ -3545,8 +3545,9 @@ push_cold_blocks_to_end(cfg_builder *g) { if (!IS_LABEL(b->b_next->b_label)) { b->b_next->b_label.id = next_lbl++; } - basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id, - NO_LOCATION, NULL); + RETURN_IF_ERROR( + basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, + b->b_next->b_label.id, NO_LOCATION, NULL)); explicit_jump->b_cold = 1; explicit_jump->b_next = b->b_next; explicit_jump->b_predecessors = 1; _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
