Skip to content

Commit 1bf59a3

Browse files
committed
Update delegate invoke helper
1 parent 432bcc1 commit 1bf59a3

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/cswinrt/code_writers.h

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9095,23 +9095,39 @@ AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(@), s
90959095
else
90969096
{
90979097
w.write(R"(
9098+
if (!RuntimeFeature.IsDynamicCodeCompiled)
9099+
{
9100+
AbiToProjectionVftablePtr = %.AbiToProjectionVftablePtr;
9101+
}
9102+
else
9103+
{
9104+
#if NET8_0_OR_GREATER
9105+
[RequiresDynamicCode("Generic instantiations might not be available in AOT scenarios.")]
9106+
#endif
9107+
[MethodImpl(MethodImplOptions.NoInlining)]
9108+
static void InitializeAbiToProjectionVftablePtrFallback()
9109+
{
90989110
%
90999111
9100-
if (RuntimeFeature.IsDynamicCodeCompiled && %.AbiToProjectionVftablePtr == default)
9112+
if (%.AbiToProjectionVftablePtr == default)
91019113
{
9102-
AbiInvokeDelegate = %;
9103-
AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(@%), sizeof(IntPtr) * 4);
9104-
*(global::WinRT.Interop.IUnknownVftbl*)AbiToProjectionVftablePtr = global::WinRT.Interop.IUnknownVftbl.AbiToProjectionVftbl;
9105-
((IntPtr*)AbiToProjectionVftablePtr)[3] = Marshal.GetFunctionPointerForDelegate(AbiInvokeDelegate);
9114+
AbiInvokeDelegate = %;
9115+
AbiToProjectionVftablePtr = ComWrappersSupport.AllocateVtableMemory(typeof(@%), sizeof(IntPtr) * 4);
9116+
*(global::WinRT.Interop.IUnknownVftbl*)AbiToProjectionVftablePtr = global::WinRT.Interop.IUnknownVftbl.AbiToProjectionVftbl;
9117+
((IntPtr*)AbiToProjectionVftablePtr)[3] = Marshal.GetFunctionPointerForDelegate(AbiInvokeDelegate);
91069118
}
91079119
else
91089120
{
9109-
AbiToProjectionVftablePtr = %.AbiToProjectionVftablePtr;
9121+
AbiToProjectionVftablePtr = %.AbiToProjectionVftablePtr;
9122+
}
9123+
}
9124+
9125+
InitializeAbiToProjectionVftablePtrFallback();
91109126
}
91119127
)",
91129128
!have_generic_params ? "" :
91139129
w.write_temp(R"(
9114-
if (RuntimeFeature.IsDynamicCodeCompiled && (%.AbiToProjectionVftablePtr == default || %._Invoke == default))
9130+
if ((%.AbiToProjectionVftablePtr == default || %._Invoke == default))
91159131
{
91169132
Abi_Invoke_Type = Expression.GetDelegateType(new Type[] { typeof(void*), %typeof(int) });
91179133
}

0 commit comments

Comments
 (0)