-
Notifications
You must be signed in to change notification settings - Fork 202
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
SafeHandle marshalling #133
SafeHandle marshalling #133
Conversation
Extend the MarshallingInfo discriminated union to not only represent attribute info but to also represent any other marshalling info that requires a Compilation object to determine. This avoids having to plumb passing down a compilation object through 4 API layers and makes the marshaller selection switch statement a little bit simpler.
… using xunit asserts that currently we just call directly in the Demo.
…mentation to explain the overall logic of SafeHandle marshaller. Signed-off-by: Jeremy Koritzinsky <[email protected]>
/// where native values will leak if we | ||
/// fail to unmarshal, but do run cleanup. | ||
/// </summary> | ||
LeakSafeUnmarshal |
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.
It may be useful to have a comment that describes the overall structure of the method to make it clear how the stages fit together. Something like:
... Setup ...
try
{
... Marshal ...
fixed (... Pin ...)
{
... Invoke ...
}
... Unmarshal ...
}
finally
{
... Cleanup...
}
... KeepAlive ...
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.
This is something we are attempting to push into the design documents: https://github.com/dotnet/runtimelab/blob/DllImportGenerator/DllImportGenerator/designs/Pipeline.md
Which also need to be updated with these new stages.
DllImportGenerator/DllImportGenerator/Marshalling/SafeHandleMarshaller.cs
Outdated
Show resolved
Hide resolved
/// where native values will leak if we | ||
/// fail to unmarshal, but do run cleanup. | ||
/// </summary> | ||
LeakSafeUnmarshal |
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.
This is something we are attempting to push into the design documents: https://github.com/dotnet/runtimelab/blob/DllImportGenerator/DllImportGenerator/designs/Pipeline.md
Which also need to be updated with these new stages.
DllImportGenerator/DllImportGenerator/Marshalling/SafeHandleMarshaller.cs
Outdated
Show resolved
Hide resolved
…rshaller.cs Co-authored-by: Jan Kotas <[email protected]>
I think exception thrown during cleanup should be a non-scenario. |
Any more feedback? |
InvocationExpression( | ||
MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, | ||
ParseTypeName(TypeNames.System_Runtime_InteropServices_MarshalEx), | ||
IdentifierName("SetHandle")), |
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.
Being a guest here, but happened to see this is the only that doesn't currently use nameof?
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.
The MarshalEx type isn't a type in the .NET Standard 2.0 contract, so we can't use nameof
for any of its methods. It's currently in Ancillary.Interop. In the future its methods will move into dotnet/runtime in some fashion.
Co-authored-by: Jan Kotas <[email protected]> Commit migrated from dotnet/runtimelab@2cde5aa
Implement default marshalling for SafeHandles using both CoreCLR and CoreRT's implementations as a baseline.
Introduce a new phase : "LeakSafeUnmarshal" to represent unmarshalling steps that cause leaks if skipped in exceptional cases.
Since we don't have access to a
Compilation
object inMarshallingGenerators.TryCreate
and plumbing one down there requires passing it through 3 or 4 layers of the API, I've renamed theMarshallingAttributeInfo
distriminated union toMarshallingInfo
and extended it to also represent marshalling info that requires aCompilation
object to calculate it.I've added some xunit-like execution tests in the Demo project that the Main method just calls directly until we decide how we want to do our execution testing.