Skip to content

[mypyc] Make list get/set item more memory safe on free-threaded builds#21683

Merged
JukkaL merged 2 commits into
masterfrom
mypyc-safe-list-2
Jul 6, 2026
Merged

[mypyc] Make list get/set item more memory safe on free-threaded builds#21683
JukkaL merged 2 commits into
masterfrom
mypyc-safe-list-2

Conversation

@JukkaL

@JukkaL JukkaL commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Use the CPython C API for list get item and set item, as direct item access is not memory safe in the presence of race conditions on a free-threaded Python.

Note that these operations are not necessarily atomic -- this only fixes memory safety. Explicit synchronization is still generally expected for correctness.

This still doesn't cover for loops over lists. I will fix them in a follow-up PR.

Preserve existing optimized primitives on non-free-threaded builds.

Work on mypyc/mypyc#1202.

@JukkaL JukkaL merged commit cd747e5 into master Jul 6, 2026
18 checks passed
@JukkaL JukkaL deleted the mypyc-safe-list-2 branch July 6, 2026 16:02
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