Skip to content

Commit f428c36

Browse files
committed
Changed the implementation of how the AnyCPU implementation calls the native methods and throw an exception when an unsupported architecture is detected.
1 parent bf7be94 commit f428c36

File tree

4 files changed

+178
-109
lines changed

4 files changed

+178
-109
lines changed

src/Magick.NET/Helpers/Runtime.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,20 @@ namespace ImageMagick;
88

99
internal static partial class Runtime
1010
{
11-
public static bool Is64Bit { get; } = IntPtr.Size == 8;
11+
public static bool Is64Bit { get; } = Architecture is Architecture.X64 or Architecture.Arm64;
1212

13-
public static bool IsArm64 { get; } = RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
13+
public static Architecture Architecture { get; } = GetArchitecture();
1414

1515
public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
16+
17+
private static Architecture GetArchitecture()
18+
{
19+
var processArchitecture = RuntimeInformation.ProcessArchitecture;
20+
21+
return processArchitecture switch
22+
{
23+
Architecture.X64 or Architecture.Arm64 or Architecture.X86 => processArchitecture,
24+
_ => throw new NotSupportedException($"{processArchitecture} is an unsupported architecture, only {nameof(Architecture.X64)}, {nameof(Architecture.Arm64)} and {nameof(Architecture.X86)} are supported."),
25+
};
26+
}
1627
}

src/Magick.NET/Native/NativeLibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal static class NativeLibrary
1313

1414
public const string X64Name = Name + "-" + QuantumName + "-x64.dll";
1515

16-
public const string ARM64Name = Name + "-" + QuantumName + "-arm64.dll";
16+
public const string Arm64Name = Name + "-" + QuantumName + "-arm64.dll";
1717

1818
#if Q8
1919
private const string Quantum = "Q8";

tests/Magick.NET.Tests/TestHelpers/TestRuntime.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ namespace Magick.NET.Tests;
88

99
internal static class TestRuntime
1010
{
11-
public static bool HasFlakyLinuxArm64Result
12-
=> IsLinux && Runtime.IsArm64;
11+
public static bool HasFlakyLinuxArm64Result { get; } = IsLinux && Runtime.Architecture is Architecture.Arm64;
1312

14-
public static bool HasFlakyMacOSResult
15-
=> IsMacOS;
13+
public static bool HasFlakyMacOSResult { get; } = IsMacOS;
1614

17-
public static bool HasFlakyMacOSArm64Result
18-
=> IsMacOS && Runtime.IsArm64;
15+
public static bool HasFlakyMacOSArm64Result { get; } = IsMacOS && Runtime.Architecture is Architecture.Arm64;
1916

2017
private static bool IsLinux { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
2118

0 commit comments

Comments
 (0)