-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Cleanup callee-allocated-only resources only if the call succeeds #89822
Conversation
Tagging subscribers to this area: @dotnet/interop-contrib Issue DetailsThis PR separates cleaning up caller allocated resources and callee allocated resources into separate stages in the managed to unmanaged direction. Caller allocated parameters (anything except 'out') will clean up the same way. Callee allocated parameters ('out' parameters) will be cleaned up only if the invocation succeeded. To do this, we check if the marshal direction is only from the unmanaged callee, and if so, we add the cleanup statements to the CleanupCalleeAllocated stage. Otherwise, it is added to the CleanupCallerAllocated stage. [Out] arrays now need to follow the same behavior for the elements of the array. Once the test types from #89583 are merged into main, I'll create a diff of the generated code.
|
@jtschuster is this ready for review? |
I messed up with git and this also has most of the changes from the follow up PR. I'm trying to clean it back to what it originally was, but it might be easiest to just look at #89971. |
See generated code diff at https://github.com/jtschuster/GeneratedCode/pull/4/files (outdated now)
This PR separates cleaning up caller allocated resources and callee allocated resources into separate stages in the managed to unmanaged direction. Caller allocated parameters (anything except 'out') will clean up the same way. Callee allocated parameters ('out' parameters) will be cleaned up only if the invocation succeeded.
To do this, we check if the marshal direction is only from the unmanaged callee, and if so, we add the cleanup statements to the CleanupCalleeAllocated stage. Otherwise, it is added to the CleanupCallerAllocated stage.
Fixes #89896
[Out] arrays now need to follow the same behavior for the elements of the array (issue: #89897, pr: #89971).