Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions Lib/test/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ def test_assemble_init_allocation_failure(self):
""")
script_helper.assert_python_ok('-c', code)

@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")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a crash when an allocation failure occurred while compiling code
containing cold blocks.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see this crash? Can you add a test that reproduces it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done it

5 changes: 3 additions & 2 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -3546,8 +3546,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);
RETURN_IF_ERROR(
basicblock_addop(explicit_jump, JUMP_NO_INTERRUPT,
b->b_next->b_label.id, NO_LOCATION));
explicit_jump->b_cold = 1;
explicit_jump->b_next = b->b_next;
explicit_jump->b_predecessors = 1;
Expand Down
Loading