Skip to content

Commit 9cd2f46

Browse files
Merge remote-tracking branch 'upstream/main'
2 parents b939b84 + e0d1ef2 commit 9cd2f46

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎Lib/test/test_compile.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ def test_assemble_init_allocation_failure(self):
6464
""")
6565
script_helper.assert_python_ok('-c', code)
6666

67+
@support.requires_subprocess()
68+
@support.nomemtest
69+
def test_push_cold_blocks_to_end_allocation_failure(self):
70+
code = textwrap.dedent("""
71+
from test import support
72+
73+
source = "async def f():\\n await x\\n"
74+
for n in range(1, 1000):
75+
with support.inject_memory_error_cm(n, n + 1):
76+
try:
77+
compile(source, "<test>", "exec")
78+
except MemoryError:
79+
continue
80+
break
81+
else:
82+
raise AssertionError("compile() never succeeded")
83+
if n == 1:
84+
raise AssertionError("no MemoryError raised")
85+
""")
86+
script_helper.assert_python_ok('-c', code)
87+
6788
def test_other_newlines(self):
6889
compile("\r\n", "<test>", "exec")
6990
compile("\r", "<test>", "exec")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fixed a crash when an allocation failure occurred while compiling code
2+
containing cold blocks.

‎Python/flowgraph.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3557,8 +3557,9 @@ push_cold_blocks_to_end(cfg_builder *g) {
35573557
if (!IS_LABEL(b->b_next->b_label)) {
35583558
b->b_next->b_label.id = next_lbl++;
35593559
}
3560-
basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT, b->b_next->b_label.id,
3561-
NO_LOCATION, NULL);
3560+
RETURN_IF_ERROR(
3561+
basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT,
3562+
b->b_next->b_label.id, NO_LOCATION, NULL));
35623563
explicit_jump->b_cold = 1;
35633564
explicit_jump->b_next = b->b_next;
35643565
explicit_jump->b_predecessors = 1;

0 commit comments

Comments
 (0)