checkpoint

This commit is contained in:
2020-04-30 17:27:50 -04:00
parent 9bc522180d
commit 9aa367e9f5
16 changed files with 176 additions and 98 deletions

48
Alpm/ExtensionMethods.cs Normal file
View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.ConstrainedExecution;
namespace Foodsoft.Alpm
{
public static class ExtensionMethods
{
[PrePrepareMethod]
public static Package? FindSatisfier(this IEnumerable<Package> pkgList, string depString)
{
var refs = new Dictionary<IntPtr, Package?>(10);
var listPtr = IntPtr.Zero;
RuntimeHelpers.PrepareConstrainedRegions();
try
{
foreach (var pkg in pkgList)
{
var release = false;
var handle = pkg.Handle;
var pkgPtr = handle.DangerousGetHandle();
refs.Add(pkgPtr, null);
handle.DangerousAddRef(ref release);
if (!release) throw new ObjectDisposedException(handle.GetType().FullName);
refs[pkgPtr] = pkg;
listPtr = alpm.alpm_list_add(listPtr, handle.DangerousGetHandle());
}
var foundPtr = alpm.alpm_find_satisfier(listPtr, depString);
return foundPtr != IntPtr.Zero
? refs[foundPtr]
: null;
}
finally
{
alpm.alpm_list_free(listPtr);
foreach (var pkg in refs.Values)
{
pkg?.Handle.DangerousRelease();
}
}
}
}
}