Skip to content

gh-137030: Fix YIELD_VALUE bytecode assertion#149184

Open
vstinner wants to merge 2 commits intopython:mainfrom
vstinner:for_iter_gen
Open

gh-137030: Fix YIELD_VALUE bytecode assertion#149184
vstinner wants to merge 2 commits intopython:mainfrom
vstinner:for_iter_gen

Conversation

@vstinner
Copy link
Copy Markdown
Member

@vstinner vstinner commented Apr 30, 2026

Expect also INSTRUMENTED_FOR_ITER.
@vstinner
Copy link
Copy Markdown
Member Author

@Fidget-Spinner @markshannon @emmatyping: Would you mind to review this fix?

See #137030 (comment) to reproduce the issue.

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Apr 30, 2026

Documentation build overview

📚 cpython-previews | 🛠️ Build #32485691 | 📁 Comparing a28cf41 against main (4599335)

  🔍 Preview build  

16 files changed · ± 16 modified

± Modified

Comment thread Python/bytecodes.c Outdated
@@ -1781,6 +1781,7 @@ dummy_func(
#if TIER_ONE
assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
Copy link
Copy Markdown
Member

@markshannon markshannon Apr 30, 2026

Choose a reason for hiding this comment

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

I'm not sure there's much value in this assert any more.
I'd be fine with removing the whole thing.

If you want to keep the check, this

Suggested change
assert(frame->instr_ptr->op.code == INSTRUMENTED_LINE ||
#if TIER_ONE && defined(Py_DEBUG)
if (!PyStackRef_IsNone(frame->f_executable)) {
int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), frame->instr_ptr - _PyFrame_GetBytecode(frame)).op.code;
assert(opcode == SEND || opcode == FOR_ITER);
}
#endif

is probably a better formulation as it catches errors that would be hidden behind instrumentation.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, I updated my PR to use _Py_GetBaseCodeUnit().

Co-Authored-by: Mark Shannon <mark@hotpy.org>
@markshannon
Copy link
Copy Markdown
Member

@emmatyping can you confirm that this fixes the issue?

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