Skip to content

Convert more COM interop MethodDescCallSite to UCO#125508

Closed
am11 wants to merge 26 commits intodotnet:mainfrom
am11:feature/MDCS-to-UCOA-pattern
Closed

Convert more COM interop MethodDescCallSite to UCO#125508
am11 wants to merge 26 commits intodotnet:mainfrom
am11:feature/MDCS-to-UCOA-pattern

Conversation

@am11
Copy link
Member

@am11 am11 commented Mar 12, 2026

Contributes to #123864 (group 5: except dispatchinfo.cpp)

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Mar 12, 2026
@am11 am11 closed this Mar 19, 2026
@am11 am11 deleted the feature/MDCS-to-UCOA-pattern branch March 19, 2026 16:39
@jkotas
Copy link
Member

jkotas commented Mar 20, 2026

This was close to being merged, except the InvokeArgSlot one that needs more work so that we are confident about it. Would you like to resubmit the delta without InvokeArgSlot?

@am11 am11 restored the feature/MDCS-to-UCOA-pattern branch March 20, 2026 10:50
@am11 am11 reopened this Mar 20, 2026
@am11
Copy link
Member Author

am11 commented Mar 20, 2026

Failures are known/unrelated.

INT_PTR queriedInterface = reinterpret_cast<INT_PTR>(*ppUnkOut);
INT32 result = static_cast<INT32>(CustomQueryInterfaceResult::NotHandled);
UnmanagedCallersOnlyCaller callICustomQueryInterface(METHOD__STUBHELPERS__CALL_ICUSTOM_QUERY_INTERFACE);
callICustomQueryInterface.InvokeThrowing(&pObj, &guid, &queriedInterface, &result);
Copy link
Member

Choose a reason for hiding this comment

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

There is also InvokeThrowing_Ret that can be used to return primitives. We use it in a few places and in this case probably is easier to read. You can then also update the managed signature to be more "natural".

DEFINE_METHOD(STUBHELPERS, GET_IENUMERATOR_TO_ENUM_VARIANT_MARSHALER, GetIEnumeratorToEnumVariantMarshaler, SM_PtrObj_PtrException_RetVoid)
DEFINE_METHOD(STUBHELPERS, GET_DISPATCH_EX_PROPERTY_FLAGS, GetDispatchExPropertyFlags, SM_PtrPropertyInfo_PtrInt_PtrException_RetVoid)
DEFINE_METHOD(STUBHELPERS, CALL_ICUSTOM_QUERY_INTERFACE, CallICustomQueryInterface, SM_PtrICustomQueryInterface_PtrGuid_PtrIntPtr_PtrInt_PtrException_RetVoid)
DEFINE_METHOD(STUBHELPERS, INVOKE_CONNECTION_POINT_PROVIDER_METHOD, InvokeConnectionPointProviderMethod, SM_PtrObj_IntPtr_PtrObj_IntPtr_PtrObj_IntPtr_Bool_PtrException_RetVoid)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
DEFINE_METHOD(STUBHELPERS, INVOKE_CONNECTION_POINT_PROVIDER_METHOD, InvokeConnectionPointProviderMethod, SM_PtrObj_IntPtr_PtrObj_IntPtr_PtrObj_IntPtr_Bool_PtrException_RetVoid)
DEFINE_METHOD(STUBHELPERS, INVOKE_CONNECTION_POINT_PROVIDER_METHOD, InvokeConnectionPointProviderMethod, NoSig)

This should be nosig now that it has unmanaged pointers in the signatures (encoding the unmanaged pointers in the signature here is not worth the pain).

Comment on lines +2564 to +2569
INT_PTR queriedInterface = reinterpret_cast<INT_PTR>(*ppUnkOut);
INT32 result = static_cast<INT32>(CustomQueryInterfaceResult::NotHandled);
UnmanagedCallersOnlyCaller callICustomQueryInterface(METHOD__STUBHELPERS__CALL_ICUSTOM_QUERY_INTERFACE);
callICustomQueryInterface.InvokeThrowing(&pObj, &guid, &queriedInterface, &result);

*ppUnkOut = reinterpret_cast<IUnknown*>(queriedInterface);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
INT_PTR queriedInterface = reinterpret_cast<INT_PTR>(*ppUnkOut);
INT32 result = static_cast<INT32>(CustomQueryInterfaceResult::NotHandled);
UnmanagedCallersOnlyCaller callICustomQueryInterface(METHOD__STUBHELPERS__CALL_ICUSTOM_QUERY_INTERFACE);
callICustomQueryInterface.InvokeThrowing(&pObj, &guid, &queriedInterface, &result);
*ppUnkOut = reinterpret_cast<IUnknown*>(queriedInterface);
INT32 result = static_cast<INT32>(CustomQueryInterfaceResult::NotHandled);
UnmanagedCallersOnlyCaller callICustomQueryInterface(METHOD__STUBHELPERS__CALL_ICUSTOM_QUERY_INTERFACE);
callICustomQueryInterface.InvokeThrowing(&pObj, &guid, ppUnkOut, &result);

We do not need a local copy of the IUnknown. This should also reduce changes that the IUknown reference leak if an exception is thrown in a specific spot.

@am11
Copy link
Member Author

am11 commented Mar 20, 2026

PR was already approved and we had a good checkpoint with all tests passing. Now I have to go back to debug the new issues in additional changes made in last two hours. I will park this for now from my side. If someone else has time, feel free to continue (curl -sSL https://github.com/dotnet/runtime/pull/125508.patch | git apply -).

@am11 am11 closed this Mar 20, 2026
@am11 am11 deleted the feature/MDCS-to-UCOA-pattern branch March 20, 2026 17:07
@jkotas
Copy link
Member

jkotas commented Mar 20, 2026

Asked copilot to continue: #125849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-VM-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants