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

Make StructLayout work on Mono 64-bit #22794

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Workspaces/Core/Portable/Workspace/Solution/Checksum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ public static string GetChecksumsLogInfo(IEnumerable<Checksum> checksums)
/// This structure stores the 20-byte SHA 1 hash as an inline value rather than requiring the use of
/// <c>byte[]</c>.
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 20)]
/// <remarks>
/// Pack = 4 is specified to work around a Mono runtime behavior where on 64-bit the size of the
/// struct would be 24 and not 20 due to alignment (it ignores Size = 20, but Pack = 4 does it).
/// Without this fix the ctor would throw because it would use sizeof(Sha1Hash) == 24.
/// </remarks>
[StructLayout(LayoutKind.Explicit, Size = 20, Pack = 4)]
Copy link
Member

Choose a reason for hiding this comment

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

Why does this even use StructLayout at all? Are we using this for blitting with something else? Can we update the doc to point to where that is being done?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a question for @sharwell I presume. I would prefer to avoid digging too deep into this code since I don't understand it.

Copy link
Member

Choose a reason for hiding this comment

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

@jasonmalinowski Considering this is a private nested type, the current comment and usage ~50 lines above seems to address the situation. It was certainly enough for Kirill to make the correct change in response to the Mono bug (coming in from never seeing it before).

Copy link
Member

Choose a reason for hiding this comment

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

My motto is if somebody had to ask, your comments are never sufficient. 😄 Is the blitting above the only reason? If I just rewrote the ToString to not allocate the array entirely...could I remove this?

private struct Sha1Hash : IEquatable<Sha1Hash>
{
[FieldOffset(0)]
Expand Down