Skip to content

[mypyc] Fix crash on accessing StopAsyncIteration#21406

Merged
p-sawicki merged 8 commits intopython:masterfrom
p-sawicki:fix-crash-stop-async-iteration
May 5, 2026
Merged

[mypyc] Fix crash on accessing StopAsyncIteration#21406
p-sawicki merged 8 commits intopython:masterfrom
p-sawicki:fix-crash-stop-async-iteration

Conversation

@p-sawicki
Copy link
Copy Markdown
Collaborator

Using StopAsyncIteration in raise expressions or as the caught type in except blocks crashes at runtime because the generated code loads the address of the PyExc_StopAsyncIteration variable and casts it to PyObject *. The variable itself is already a PyObject * so its address being interpreted as PyObject * is incorrect.

To fix, add a special case to use LoadGlobal instead of LoadAddress for builtin type variables that are already PyObject *.

Comment thread mypyc/primitives/registry.py Outdated


def load_address_op(name: str, type: RType, src: str) -> LoadAddressDescription:
def load_address_op(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Now the name doesn't quite match the intent -- it either loads the address or the value of the name. Instead of adding a bool flag to the control for address/value, I think it would be better to add a new dictionary for something like load_global_op(<fullname>, <type>, <c_name>). This way the pre-existing buildin_names dictionary wouldn't have to be touched at all, I think.

@p-sawicki p-sawicki merged commit bb3e497 into python:master May 5, 2026
17 checks passed
@p-sawicki p-sawicki deleted the fix-crash-stop-async-iteration branch May 5, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants