-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
[LibraryImportGenerator] Basic stateless value marshaller support #71116
Conversation
Does not handle caller-allocated buffer or linear collections
Tagging subscribers to this area: @dotnet/interop-contrib Issue Details
This only adds really basic support for stateless value marshalling. It doesn't deal with:
As I was doing this, I realized a lot of the initial work - splitting out V1, adding new shapes - would probably collide with what needs when he starts the analyzer side @AaronRobinsonMSFT, so I wanted to get just the basics out first (also wanted to avoid mixing together so much rename/reorganize with new support). Generated examplepublic static partial void ReverseStrings(ref global::SharedTypes.StringContainer strings)
{
global::SharedTypes.StringContainerMarshaller.StringContainerNative __strings_native = default;
try
{
// Marshal - Convert managed data to native data.
__strings_native = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToUnmanaged(strings);
{
__PInvoke(&__strings_native);
}
// Unmarshal - Convert native data to managed data.
strings = global::SharedTypes.StringContainerMarshaller.Ref.ConvertToManaged(__strings_native);
}
finally
{
// Cleanup - Perform required cleanup.
global::SharedTypes.StringContainerMarshaller.Ref.Free(__strings_native);
}
// Local P/Invoke
[System.Runtime.InteropServices.DllImportAttribute("Microsoft.Interop.Tests.NativeExportsNE", EntryPoint = "stringcontainer_reverse_strings", ExactSpelling = true)]
static extern unsafe void __PInvoke(global::SharedTypes.StringContainerMarshaller.StringContainerNative* strings);
}
|
...ervices/gen/Microsoft.Interop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be nice to split out the CustomTypeMarshalling tests in LibraryImportGenerator.Tests into a class/file for the V1 shapes and a new class/file for the new shapes instead of having them in the same file.
Other than that, LGTM
…erop.SourceGeneration/Marshalling/ICustomTypeMarshallingStrategy.cs Co-authored-by: Aaron Robinson <[email protected]>
_V1
classesThis only adds really basic support for stateless value marshalling. It doesn't deal with:
GetPinnableReference
on the marshallerAs I was doing this, I realized a lot of the initial work - splitting out V1, adding new shapes - would probably collide with what @AaronRobinsonMSFT needs when he starts the analyzer side, so I wanted to get just some of the basics out first (also wanted to avoid mixing together so much renaming/reorganization with new support).
Generated example