Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace some unsafe system executor code with safe code #8274

Merged
merged 4 commits into from
Mar 31, 2023

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Mar 31, 2023

Objective

The function SyncUnsafeCell::from_mut returns &SyncUnsafeCell<T>, even though it could return &mut SyncUnsafeCell<T>. This means it is not possible to call get_mut on the returned value, so you need to use unsafe code to get exclusive access back.

Solution

Return &mut Self instead of &Self in SyncUnsafeCell::from_mut. This is consistent with my proposal for UnsafeCell::from_mut: rust-lang/libs-team#198.

Replace an unsafe pointer dereference with a safe call to get_mut.


Changelog

  • The function bevy_utils::SyncUnsafeCell::get_mut now returns a value of type &mut SyncUnsafeCell<T>. Previously, this returned an immutable reference.

Migration Guide

The function bevy_utils::SyncUnsafeCell::get_mut now returns a value of type &mut SyncUnsafeCell<T>. Previously, this returned an immutable reference.

@JoJoJet JoJoJet added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels Mar 31, 2023
@james7132 james7132 requested a review from maniwani March 31, 2023 16:11
crates/bevy_utils/src/syncunsafecell.rs Outdated Show resolved Hide resolved
@james7132 james7132 added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 31, 2023
@james7132 james7132 added this pull request to the merge queue Mar 31, 2023
Merged via the queue into bevyengine:main with commit ae39b07 Mar 31, 2023
@JoJoJet JoJoJet deleted the sync-unsafe-cell-safety branch March 31, 2023 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide C-Code-Quality A section of code that is hard to understand or change S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants