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

Create a doc outlining ownership rules for the ComInterfaceGenerator #88203

Closed

Conversation

jtschuster
Copy link
Member

We've been hitting some issues with ownership and lifetimes in the COM interface generator, so to avoid adding patches to fix issues as we hit them and add complexity, we thought it would be good to outline the rules as simply and generally as we can before making any more changes.

The main premise is that the ownership transfer rules depend on the level of indirection (by value, pointer, pointer to pointer), whether the type is an array or not, and the ownership annotations ([In], [Out], in, out, ref).

@ghost
Copy link

ghost commented Jun 29, 2023

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

Issue Details

We've been hitting some issues with ownership and lifetimes in the COM interface generator, so to avoid adding patches to fix issues as we hit them and add complexity, we thought it would be good to outline the rules as simply and generally as we can before making any more changes.

The main premise is that the ownership transfer rules depend on the level of indirection (by value, pointer, pointer to pointer), whether the type is an array or not, and the ownership annotations ([In], [Out], in, out, ref).

Author: jtschuster
Assignees: -
Labels:

area-System.Runtime.InteropServices

Milestone: -

@@ -0,0 +1,155 @@
# Ownership and Lifetimes of parameters
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT Jun 30, 2023

Choose a reason for hiding this comment

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

The content here is good. Perhaps there is a more effective way to organize/represent it. Have you considered the pivot being the type and then have examples (both C# and C/C++) for each. Below is a sketch, but note the type, not the indirection, is the primary pivot. Then below it are the ways to pass the type with an example in C# and the same signature in C/C++/IDL. This let's users easily determine the type they are using and then find an example on how it is being used.

## Primitives

### By Value

### By Reference

C# - void Method(ref int a);
COM - HRESULT Method(int* a);

## Array

### By Value - Blittable

C# - void Method(int[] a);
COM - HRESULT Method(int* a);

@danmoseley
Copy link
Member

Is this only applicable to this repo or should it go in docs (similar to how we moved our interop doc to make a great public doc)?

@AaronRobinsonMSFT
Copy link
Member

Is this only applicable to this repo or should it go in docs (similar to how we moved our interop doc to make a great public doc)?

Excellent suggestion @danmoseley. I think this is in line with the Interop team's focus on improving docs. I think having a page with this content under https://learn.microsoft.com/dotnet/standard/native-interop/cominterop would be most welcome to all.

@jtschuster Thoughts?

@jtschuster
Copy link
Member Author

Is this only applicable to this repo or should it go in docs (similar to how we moved our interop doc to make a great public doc)?

Excellent suggestion @danmoseley. I think this is in line with the Interop team's focus on improving docs. I think having a page with this content under https://learn.microsoft.com/dotnet/standard/native-interop/cominterop would be most welcome to all.

@jtschuster Thoughts?

That's a good idea, I'll make some changes to make it more suitable for public docs.

@jtschuster
Copy link
Member Author

This will be going into public docs instead

@jtschuster jtschuster closed this Aug 2, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 1, 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.

3 participants