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

Remove Resurrect logic as it shouldn't be needed for .NET 6 and newer. #1380

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions src/WinRT.Runtime/ComWrappersSupport.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ internal static unsafe InspectableInfo GetInspectableInfo(IntPtr pThis)
// We need to do the same thing for System.Type because there can be multiple WUX.Interop.TypeName's
// for a single System.Type.

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
if (rcw is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}

return rcw switch
{
ABI.System.Nullable nt => (T)nt.Value,
Expand Down Expand Up @@ -160,15 +154,7 @@ public static void RegisterObjectForInterface(object obj, IntPtr thisPtr) =>

public static object TryRegisterObjectForInterface(object obj, IntPtr thisPtr)
{
var rcw = ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);

// Resurrect IWinRTObject's disposed IObjectReferences, if necessary
var target = rcw is Delegate del ? del.Target : rcw;
if (target is IWinRTObject winrtObj)
{
winrtObj.Resurrect();
}
return rcw;
return ComWrappers.GetOrRegisterObjectForComInstance(thisPtr, CreateObjectFlags.TrackerObject, obj);
}

public static IObjectReference CreateCCWForObject(object obj)
Expand Down
18 changes: 0 additions & 18 deletions src/WinRT.Runtime/IWinRTObject.net5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,5 @@ object GetOrCreateTypeHelperData(RuntimeTypeHandle type, Func<object> helperData
{
return AdditionalTypeData.GetOrAdd(type, (type) => helperDataFactory());
}

internal void Resurrect()
{
if (NativeObject.Resurrect())
{
foreach (var cached in QueryInterfaceCache)
{
cached.Value.Resurrect();
}

// Delegates store their agile reference as an additional type data.
// These should be recreated when instances are resurrect.
if (AdditionalTypeData.TryGetValue(typeof(AgileReference).TypeHandle, out var agileObj))
{
AdditionalTypeData.TryUpdate(typeof(AgileReference).TypeHandle, new AgileReference(NativeObject), agileObj);
}
}
}
}
}
38 changes: 5 additions & 33 deletions src/WinRT.Runtime/ObjectReference.cs
jlaanstra marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ public IntPtr GetRef()

protected void ThrowIfDisposed()
{
if (disposed)
if (disposed)
{
lock (_disposedLock)
{
if (disposed) throw new ObjectDisposedException("ObjectReference");
}
lock (_disposedLock)
{
if (disposed) throw new ObjectDisposedException("ObjectReference");
}
}
}

Expand Down Expand Up @@ -287,22 +287,6 @@ protected virtual void Dispose(bool disposing)
}
}

internal bool Resurrect()
{
lock (_disposedLock)
{
if (!disposed)
{
return false;
}
disposed = false;
ResurrectTrackerSource();
AddRef();
GC.ReRegisterForFinalize(this);
return true;
}
}

protected virtual unsafe void AddRef(bool refFromTrackerSource)
{
VftblIUnknown.AddRef(ThisPtr);
Expand Down Expand Up @@ -353,18 +337,6 @@ internal unsafe void ReleaseFromTrackerSource()
}
}

private unsafe void ResurrectTrackerSource()
{
if (ReferenceTrackerPtr != IntPtr.Zero)
{
ReferenceTracker.IUnknownVftbl.AddRef(ReferenceTrackerPtr);
if (!PreventReleaseFromTrackerSourceOnDispose)
{
ReferenceTracker.AddRefFromTrackerSource(ReferenceTrackerPtr);
}
}
}

private unsafe void DisposeTrackerSource()
{
if (ReferenceTrackerPtr != IntPtr.Zero)
Expand Down