Skip to content

Fix failures around blittable collections with [Out] and chars #89149

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

Merged
merged 5 commits into from
Jul 19, 2023

Conversation

jkoritzinsky
Copy link
Member

Fixes #88708

@jkoritzinsky jkoritzinsky added area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature labels Jul 18, 2023
@jkoritzinsky jkoritzinsky added this to the 8.0.0 milestone Jul 18, 2023
@ghost
Copy link

ghost commented Jul 18, 2023

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #88708

Author: jkoritzinsky
Assignees: -
Labels:

area-System.Runtime.InteropServices, source-generator

Milestone: 8.0.0

@ghost ghost assigned jkoritzinsky Jul 18, 2023
@@ -124,7 +128,8 @@ public IEnumerable<StatementSyntax> Generate(TypePositionInfo info, StubCodeCont

public bool UsesNativeIdentifier(TypePositionInfo info, StubCodeContext context)
{
return context.IsInStubReturnPosition(info) || (info.IsByRef && !context.SingleFrameSpansNativeContext);
MarshalDirection elementMarshalDirection = MarshallerHelpers.GetMarshalDirection(info, context);
return !IsPinningPathSupported(info, context) && (elementMarshalDirection != MarshalDirection.ManagedToUnmanaged || info.IsByRef);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I find it easier to reason about when can we pass the managed identifier to a native parameter without changing anything, and then this method is not that, but I'm also fine with whatever makes the most sense to you.

Suggested change
return !IsPinningPathSupported(info, context) && (elementMarshalDirection != MarshalDirection.ManagedToUnmanaged || info.IsByRef);
return !(IsPinningPathSupported(info, context) || (elementMarshalDirection == MarshalDirection.UnmanagedToManaged && !info.IsByRef));

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd rather keep it as is as the current condition better matches the code in Generate I think.

@jkoritzinsky jkoritzinsky merged commit 8ce3424 into dotnet:main Jul 19, 2023
@jkoritzinsky jkoritzinsky deleted the fix-out-blittable branch July 19, 2023 16:49
@ghost ghost locked as resolved and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime.InteropServices source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ComInterfaceGenerator generates code that doesn't compile for [Out] blittable arrays
2 participants