checkpoint for real
This commit is contained in:
@@ -1,46 +1,49 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Foodsoft.Alpm
|
||||
{
|
||||
internal struct ListRef : CriticalFinalIDisposable
|
||||
internal sealed class SafeListHandle : SafeHandle
|
||||
{
|
||||
public SafeAlpmHandle SafeAlpmHandle
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
|
||||
[PrePrepareMethod]
|
||||
get;
|
||||
}
|
||||
} = null!;
|
||||
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), PrePrepareMethod]
|
||||
public ListRef(SafeAlpmHandle handle)
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
[PrePrepareMethod]
|
||||
internal SafeListHandle(SafeAlpmHandle safeAlpmHandle)
|
||||
: base(IntPtr.Zero, true)
|
||||
{
|
||||
SafeAlpmHandle = null!;
|
||||
var success = false;
|
||||
RuntimeHelpers.PrepareConstrainedRegions();
|
||||
try { }
|
||||
finally
|
||||
{
|
||||
SafeAlpmHandle = handle;
|
||||
var success = false;
|
||||
handle.DangerousAddRef(ref success);
|
||||
safeAlpmHandle.DangerousAddRef(ref success);
|
||||
if (success)
|
||||
SafeAlpmHandle = handle;
|
||||
else
|
||||
{
|
||||
SafeAlpmHandle = null!;
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
SafeAlpmHandle = safeAlpmHandle;
|
||||
}
|
||||
|
||||
if (!success)
|
||||
throw new ObjectDisposedException(GetType().FullName);
|
||||
}
|
||||
|
||||
~ListRef()
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
|
||||
protected override bool ReleaseHandle()
|
||||
{
|
||||
|
||||
SafeAlpmHandle.DangerousRelease();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
||||
public override bool IsInvalid
|
||||
{
|
||||
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success), PrePrepareMethod]
|
||||
get => SafeAlpmHandle.IsInvalid;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user