checkpoint
This commit is contained in:
48
Alpm/ExtensionMethods.cs
Normal file
48
Alpm/ExtensionMethods.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user