◐ Shell
clean mode source ↗

Replace unsafe pointer cast with AtomicPtr in PyCode by youknowone · Pull Request #7063 · RustPython/RustPython

@youknowone marked this pull request as ready for review

February 9, 2026 12:06

coderabbitai[bot]

Add `source_path: AtomicPtr<PyStrInterned>` field to `PyCode`
for interior mutability, replacing the UB-inducing
`#[allow(invalid_reference_casting)]` + `write_volatile` pattern
in `update_code_filenames`. Use atomic load/store instead of a
mutex since the operation is a simple pointer swap on a 'static
reference. Update all read sites to use `source_path()` accessor.

youknowone added a commit to youknowone/RustPython that referenced this pull request

Mar 22, 2026
Add `source_path: AtomicPtr<PyStrInterned>` field to `PyCode`
for interior mutability, replacing the UB-inducing
`#[allow(invalid_reference_casting)]` + `write_volatile` pattern
in `update_code_filenames`. Use atomic load/store instead of a
mutex since the operation is a simple pointer swap on a 'static
reference. Update all read sites to use `source_path()` accessor.