Browse Source

Providers: on .NET 5.0 and newer leverage NativeLibrary from System.Runtime.interopServices

pull/506/merge
Christoph Ruegg 5 years ago
parent
commit
abafe3b6b6
  1. 12
      src/Providers.MKL/NativeProviderLoader.cs

12
src/Providers.MKL/NativeProviderLoader.cs

@ -127,13 +127,13 @@ namespace MathNet.Numerics.Providers.Common
} }
// If we have hint path provided by the user, look there first // If we have hint path provided by the user, look there first
if (TryLoadFromDirectory(fileName, hintPath)) if (hintPath != null && TryLoadFromDirectory(fileName, hintPath))
{ {
return true; return true;
} }
// If we have an overall hint path provided by the user, look there next // If we have an overall hint path provided by the user, look there next
if (Control.NativeProviderPath != hintPath && TryLoadFromDirectory(fileName, Control.NativeProviderPath)) if (Control.NativeProviderPath != null && Control.NativeProviderPath != hintPath && TryLoadFromDirectory(fileName, Control.NativeProviderPath))
{ {
return true; return true;
} }
@ -252,6 +252,9 @@ namespace MathNet.Numerics.Providers.Common
return false; return false;
} }
#if NET5_0_OR_GREATER
return NativeLibrary.TryLoad(fullPath, out libraryHandle);
#else
// If successful this will return a handle to the library // If successful this will return a handle to the library
libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath); libraryHandle = IsUnix ? UnixLoader.LoadLibrary(fullPath) : WindowsLoader.LoadLibrary(fullPath);
if (libraryHandle == IntPtr.Zero) if (libraryHandle == IntPtr.Zero)
@ -267,9 +270,11 @@ namespace MathNet.Numerics.Providers.Common
} }
return libraryHandle != IntPtr.Zero; return libraryHandle != IntPtr.Zero;
#endif
} }
} }
#if !NET5_0_OR_GREATER
[SuppressUnmanagedCodeSecurity] [SuppressUnmanagedCodeSecurity]
[SecurityCritical] [SecurityCritical]
static class WindowsLoader static class WindowsLoader
@ -297,8 +302,9 @@ namespace MathNet.Numerics.Providers.Common
const int RTLD_NOW = 2; const int RTLD_NOW = 2;
[DllImport("libdl.so", SetLastError = true)] [DllImport("libdl", SetLastError = true)]
static extern IntPtr dlopen(String fileName, int flags); static extern IntPtr dlopen(String fileName, int flags);
} }
#endif
} }
} }

Loading…
Cancel
Save