-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[API Proposal]: Allow setting explicit packing for 32 bit platforms only. #95802
Comments
I expect this would be required, I expect that just |
I'd think that some The issue would be that checking this custom attribute could be expensive for the type loader ( |
Duplicate of #60573 |
Or as many times as needed. Statically generating all the required variants of struct at build-time is laborious (can be source generated) but less intense than the full Reflection.Emit alternative. Conditions based on APIs like |
Closing as duplicate. |
Background and motivation
In Win32 there are a number of headers that are set for single byte packing on 32 bit (notably in the shell). The 64 bit definitions use default packing in all of the cases I know of. This creates a problem for defining structs for interop when building for AnyCPU (as WinForms does). We either have to define twice or, in some cases, just ignore the packing as things align on the same boundaries they would with default 32 bit packing (which has risk if one nests struct definitions).
This is blocking us from directly utilizing the published Win32 metadata (through CsWin32) in these cases. If we could specify the packing for 32 bit we would be able to safely generate Win32 interop methods.
I believe this would require a change to the CLI and the runtime / JIT. My naive idea is that if the first byte of
PackingSize
is specified it would be the 32 bit specific packing and the second byte would be "normal" packing (as the spec limits the packing to a max of 128).API Proposal
API Usage
Alternative Designs
Perhaps introducing another attribute?
StructLayout32Attribute
?Risks
No response
The text was updated successfully, but these errors were encountered: