Skip to content

Wrap CRUBIT_THREAD_SAFE types in UnsafeCell#746

Open
copybara-service[bot] wants to merge 1 commit intomainfrom
test_886895197
Open

Wrap CRUBIT_THREAD_SAFE types in UnsafeCell#746
copybara-service[bot] wants to merge 1 commit intomainfrom
test_886895197

Conversation

@copybara-service
Copy link
Copy Markdown

@copybara-service copybara-service bot commented Mar 24, 2026

Wrap CRUBIT_THREAD_SAFE types in UnsafeCell

For types annotated with CRUBIT_THREAD_SAFE, replace the normal Rust struct
fields with a single opaque UnsafeCell<[MaybeUninit; SIZE]> body.
This enables interior mutability, allowing non-const C++ methods to be
called through shared references.

This also prevents standard Rust #[derive(Copy, Clone)] generation,
and forces an explicit alignment override since the opaque byte array body
has alignment 1.

@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 24, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

For types annotated with CRUBIT_THREAD_SAFE, replace the normal Rust struct
fields with a single opaque UnsafeCell<[MaybeUninit<u8>; SIZE]> body.
This enables interior mutability, allowing non-const C++ methods to be
called through shared references.

This also prevents standard Rust `#[derive(Copy, Clone)]` generation,
and forces an explicit alignment override since the opaque byte array body
has alignment 1.

PiperOrigin-RevId: 886895197
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.

0 participants