{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/20194","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/20194/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/20194/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/20194/events","html_url":"https://github.com/dotnet/coreclr/pull/20194","id":365071101,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE5MTA3NDY3","number":20194,"title":"Marshal fixed buffers via a memcpy.","user":{"login":"jkoritzinsky","id":1571408,"node_id":"MDQ6VXNlcjE1NzE0MDg=","avatar_url":"https://avatars2.githubusercontent.com/u/1571408?v=4","gravatar_id":"","url":"https://api.github.com/users/jkoritzinsky","html_url":"https://github.com/jkoritzinsky","followers_url":"https://api.github.com/users/jkoritzinsky/followers","following_url":"https://api.github.com/users/jkoritzinsky/following{/other_user}","gists_url":"https://api.github.com/users/jkoritzinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/jkoritzinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkoritzinsky/subscriptions","organizations_url":"https://api.github.com/users/jkoritzinsky/orgs","repos_url":"https://api.github.com/users/jkoritzinsky/repos","events_url":"https://api.github.com/users/jkoritzinsky/events{/privacy}","received_events_url":"https://api.github.com/users/jkoritzinsky/received_events","type":"User","site_admin":false},"labels":[{"id":244582102,"node_id":"MDU6TGFiZWwyNDQ1ODIxMDI=","url":"https://api.github.com/repos/dotnet/coreclr/labels/area-Interop","name":"area-Interop","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-09-28T23:23:33Z","updated_at":"2018-10-01T17:28:08Z","closed_at":null,"author_association":"MEMBER","pull_request":{"url":"https://api.github.com/repos/dotnet/coreclr/pulls/20194","html_url":"https://github.com/dotnet/coreclr/pull/20194","diff_url":"https://github.com/dotnet/coreclr/pull/20194.diff","patch_url":"https://github.com/dotnet/coreclr/pull/20194.patch"},"body":"In master, when a fixed buffer is marshaled as part of a non-blittable structure, the marshaling code treats the type of a fixed buffer field `fixed byte buffer[2]` as a regular structure. However, the custom structure generated for a fixed buffer field has only one field of the type of the buffer. See the IL below for an example:\r\n\r\n```\r\n.class nested public sequential ansi sealed beforefieldinit '<number2>e__FixedBuffer'\r\n\textends [System.Runtime]System.ValueType\r\n{\r\n\t.custom instance void [System.Runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = (\r\n\t\t01 00 00 00\r\n\t)\r\n\t.custom instance void [System.Runtime]System.Runtime.CompilerServices.UnsafeValueTypeAttribute::.ctor() = (\r\n\t\t01 00 00 00\r\n\t)\r\n\t.pack 0\r\n\t.size 2\r\n\r\n\t// Fields\r\n\t.field public uint8 FixedElementField\r\n\r\n} // end of class <number2>e__FixedBuffer\r\n```\r\n\r\n\r\n So, when this member is marshaled as a regular structure only the first member is marshaled since technically it is the only member of the structure.\r\n As a result, the rest of the data is lost.\r\n\r\n\r\nThis PR adds a new marshaler for fixed buffer fields. This marshaler does a scalar copy of the full buffer structure, which ensures all data is marshaled across. In areas where fixed buffers don't need custom behavior, the behavior matches the Nested Value Class marshaler, which was the original marshaler for fixed buffers.\r\n\r\nFixes #18521."},"comment":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/comments/425992887","html_url":"https://github.com/dotnet/coreclr/pull/20194#issuecomment-425992887","issue_url":"https://api.github.com/repos/dotnet/coreclr/issues/20194","id":425992887,"node_id":"MDEyOklzc3VlQ29tbWVudDQyNTk5Mjg4Nw==","user":{"login":"jkoritzinsky","id":1571408,"node_id":"MDQ6VXNlcjE1NzE0MDg=","avatar_url":"https://avatars2.githubusercontent.com/u/1571408?v=4","gravatar_id":"","url":"https://api.github.com/users/jkoritzinsky","html_url":"https://github.com/jkoritzinsky","followers_url":"https://api.github.com/users/jkoritzinsky/followers","following_url":"https://api.github.com/users/jkoritzinsky/following{/other_user}","gists_url":"https://api.github.com/users/jkoritzinsky/gists{/gist_id}","starred_url":"https://api.github.com/users/jkoritzinsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jkoritzinsky/subscriptions","organizations_url":"https://api.github.com/users/jkoritzinsky/orgs","repos_url":"https://api.github.com/users/jkoritzinsky/repos","events_url":"https://api.github.com/users/jkoritzinsky/events{/privacy}","received_events_url":"https://api.github.com/users/jkoritzinsky/received_events","type":"User","site_admin":false},"created_at":"2018-10-01T17:28:08Z","updated_at":"2018-10-01T17:28:08Z","author_association":"MEMBER","body":"@jkotas I figured out why that's failing on the checked build. I mistakenly assumed that all fixed buffers were blittable, forgetting that `char` and `bool` buffers won't be.\r\n"}}
{"actor":{"display_login":"jkoritzinsky"}}