Skip to content

gh-151112: Move an assert that may fail in cfg_builder_check#151153

Open
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:cfg_builder_check
Open

gh-151112: Move an assert that may fail in cfg_builder_check#151153
StanFromIreland wants to merge 1 commit into
python:mainfrom
StanFromIreland:cfg_builder_check

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Jun 9, 2026

Copy link
Copy Markdown
Member

Also found with the same reproducer, just setting nomemory at a different time. In _PyCfg_FromInstructionSequence if _PyCfgBuilder_Addop fails on the first instruction, it jumps to error and calls _PyCfgBuilder_Free(g). The entry block is still empty, but cfg_builder_check asserts g_entryblock->b_iused > 0.

If you want to reproduce, you'll have to play around a little with the start/stop for nomemory, but for me it's:

./python -c 'import _testcapi

compile("pass", "<warmup>", "single")
_testcapi.set_nomemory(40, 41)
try:
    compile("pass", "<trigger>", "single")
except MemoryError:
    pass
first = bytes(128)
second = bytes(128)'
python: Python/flowgraph.c:407: cfg_builder_check: Assertion `g->g_entryblock->b_iused > 0' failed.
Aborted                    (core dumped) ./python -c 'import _testcapi

Debug only so skipping news.

@iritkatriel iritkatriel left a comment

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.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants