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

Indicate to the compiler that Rooted<T> may be uninitialized #551

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

simonwuelker
Copy link
Contributor

Wraps Rooted::ptr in MaybeUninit so it can safely be zero-initialized.

Fixes #548

@simonwuelker
Copy link
Contributor Author

These changes also remove the Initialize bound on RootedGuard, because it is no longer needed (instead of being initialized to a default value, the ptr field is now uninitialized).

I think this is an improvement, because it is not always possible to cheaply construct default values for Initialized, for example if the type contains Box or similar things that need to be allocated.

Copy link
Member

@jdm jdm left a comment

Choose a reason for hiding this comment

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

This is subtle but looks like a solid fix for the issue that you identified. My only concern is with the set method.

mozjs/src/gc/root.rs Show resolved Hide resolved
@simonwuelker simonwuelker added this pull request to the merge queue Jan 26, 2025
Merged via the queue into servo:main with commit 87cabf4 Jan 26, 2025
27 checks passed
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.

Rooted::new_unrooted can easily cause undefined behaviour
2 participants