Repository navigation
Remove any implied ownership semantics for Win32 structs - #2235
Merged
Merged
Conversation
Damyan Pepper (damyanp)
approved these changes
Dec 7, 2022
| } | ||
|
|
||
| pub fn abi(&self) -> T::Abi { | ||
| unsafe { std::mem::transmute_copy(&self.abi) } |
Contributor
There was a problem hiding this comment.
Is Abi not constrained to be Copy? I guess we sometimes set Abi to std::mem::ManuallyDrop which would not be Copy even though semantically it usually should be.
Collaborator
Author
There was a problem hiding this comment.
Sadly, it can't be Copy. That would make it a lot simple for callers. Rust requires Copy for fields of unions but won't let me make a Copy type without generating considerably more code by essentially unrolling ManuallyDrop types and duplicating their memory layout.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WinRT structs expect any non-blittable fields to be owned and dropped as necessary. Win32 structs don't provide any ownership semantics that can be gleaned from metadata and for the most part require the caller to know whether any resources are owned by the caller or callee of any particular API.
This update solidifies this by ensuring that all non-blittable field types are stored as
ManuallyDropto make that clear. A variant ofManuallyDropis also provided and used for fields to simplify programming with the Win32 API where such fields must be accessible as references without necessarily taking ownership.I tested the Direct3D 12 sample and the warnings that Alex Dixon (@polymonster) mentioned are no longer reported when running under a debugger.
Fixes: #1410