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

Cleanup callee-allocated-only resources only if the call succeeds #89822

Closed
wants to merge 29 commits into from

Conversation

jtschuster
Copy link
Member

@jtschuster jtschuster commented Aug 1, 2023

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).

@ghost
Copy link

ghost commented Aug 1, 2023

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

Issue Details

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.

[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.

Author: jtschuster
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

@jtschuster jtschuster marked this pull request as ready for review August 2, 2023 21:40
@jtschuster jtschuster marked this pull request as draft August 4, 2023 20:31
@jkoritzinsky
Copy link
Member

@jtschuster is this ready for review?

@jtschuster
Copy link
Member Author

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.

@jtschuster
Copy link
Member Author

I messed this up with git. Refer to #90098 for the changes that should have been in this PR, and #89971 for changes that solve the issue completely.

@jtschuster jtschuster closed this Aug 7, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup out parameters in guarded if
2 participants