Skip to content

Commit

Permalink
Remove Resurrect logic as it shouldn't be needed for .NET 6 and newer. (
Browse files Browse the repository at this point in the history
#1380)

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

* Remove double check.

* Add check back.
  • Loading branch information
jlaanstra committed Jan 25, 2024
1 parent 1492035 commit 70e9541
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 66 deletions.
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
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

0 comments on commit 70e9541

Please sign in to comment.