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

Add handling for [In, Out] attributes. #380

Merged

Conversation

jkoritzinsky
Copy link
Member

Implement support for [Out] and [In, Out] on by-value arrays. Disallow usage of [In] or [Out] attributes on by reference parameters or on by value parameters where they have no effect.

Integration tests depend on #379

…w usage of [In] or [Out] attributes on by reference parameters or on by value parameters where they have no effect.
@jkoritzinsky jkoritzinsky added the area-DllImportGenerator Source Generated stubs for P/Invokes in C# label Nov 23, 2020
@jkoritzinsky
Copy link
Member Author

This is finally ready for another review pass.

if (info.IsManagedReturnPosition || (info.IsByRef && info.RefKind != RefKind.In))
if (info.IsManagedReturnPosition
|| (info.IsByRef && info.RefKind != RefKind.In)
|| (info.ByValueContentsMarshalKind & ByValueContentsMarshalKind.Out) != 0)
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use the HasFlag() function for all of these checks with ByValueContentsMarshalKind?

@@ -16,6 +16,35 @@ namespace Microsoft.Interop
CharEncoding CharEncoding
);

/// <summary>
/// Describes how to marshal the contents of a value in comparison to the value itself.
/// Only makes sense for array-like types. For example, an "out" array doesn't change the
Copy link
Member

Choose a reason for hiding this comment

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

Only makes sense for array-like types.

I'm assuming we have a nice assert or even a Diagnostic warning for the user that one is using In/Out on a type that we think is silly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we emit a diagnostic warning or error if someone applies In or Out in a case where the attribute has no effect.

@jkoritzinsky jkoritzinsky merged commit 18aa6f1 into dotnet:feature/DllImportGenerator Jan 4, 2021
@jkoritzinsky jkoritzinsky deleted the out-byval-array branch January 4, 2021 22:29
jkoritzinsky added a commit to jkoritzinsky/runtime that referenced this pull request Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-DllImportGenerator Source Generated stubs for P/Invokes in C#
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants