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 mem::zeroed with mem::MaybeUninit::uninit for large struct in Unix #136826

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

xizheyin
Copy link
Contributor

As discussion in #136737.

  • Replace mem::zeroed() with MaybeUninit::uninit() for sockaddr_storage in accept() and recvfrom() since these functions fill in the address structure
  • Replace mem::zeroed() with MaybeUninit::uninit() for pthread_attr_t in thread-related functions since pthread_attr_init() initializes the structure
  • Add references to man pages to document this behavior

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @thomcc (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 10, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@joboet joboet left a comment

Choose a reason for hiding this comment

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

I thought about this a bit. We probably can't use .assume_init() as often as I thought since the C libraries neither guarantee that the structure can be moved, nor that it is fully initialized.

@bors
Copy link
Contributor

bors commented Feb 13, 2025

☔ The latest upstream changes (presumably #136954) made this pull request unmergeable. Please resolve the merge conflicts.

… unix

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@xizheyin
Copy link
Contributor Author

That makes sense! I have removed assume_init. As far as I understand it, there is no difference in program behavior between using as_mut_ptr/as_ptr directly and using assume_init, but there is a difference in terms of intent. One does not assume that C performs the initialization, the other assumes that C must perform the initialization. So, we should just pass the pointer to C's API, and then C fills it, and it's not up to us to consider whether it's init or not. Is that correct? @thomcc

@xizheyin xizheyin requested a review from thomcc February 19, 2025 07:53
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
@xizheyin xizheyin requested a review from joboet February 19, 2025 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-unix Operating system: Unix-like S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants