@@ -22,46 +22,18 @@ public unsafe class Runtime
22
22
public static int UCS => _UCS ;
23
23
internal static readonly int _UCS = PyUnicode_GetMax ( ) <= 0xFFFF ? 2 : 4 ;
24
24
25
- #if PYTHON36
26
- const string _minor = "6" ;
27
- #elif PYTHON37
28
- const string _minor = "7" ;
29
- #elif PYTHON38
30
- const string _minor = "8" ;
31
- #elif PYTHON39
32
- const string _minor = "9" ;
33
- #else
34
- #error You must define one of PYTHON36 to PYTHON39
35
- #endif
36
-
37
- #if WINDOWS
38
- internal const string dllBase = "python3" + _minor ;
39
- #else
40
- internal const string dllBase = "python3." + _minor ;
41
- #endif
42
-
43
- #if PYTHON_WITH_PYDEBUG
44
- internal const string dllWithPyDebug = "d" ;
45
- #else
46
- internal const string dllWithPyDebug = "" ;
47
- #endif
48
- #if PYTHON_WITH_PYMALLOC
49
- internal const string dllWithPyMalloc = "m" ;
50
- #else
51
- internal const string dllWithPyMalloc = "" ;
52
- #endif
53
-
54
- // C# compiler copies constants to the assemblies that references this library.
55
- // We needs to replace all public constants to static readonly fields to allow
56
- // binary substitution of different Python.Runtime.dll builds in a target application.
57
-
58
- public static readonly string PythonDLL = _PythonDll ;
25
+ public static string PythonDLL
26
+ {
27
+ get => _PythonDll ;
28
+ set
29
+ {
30
+ if ( _isInitialized )
31
+ throw new InvalidOperationException ( "This property must be set before runtime is initialized" ) ;
32
+ _PythonDll = value ;
33
+ }
34
+ }
59
35
60
- #if PYTHON_WITHOUT_ENABLE_SHARED && ! NETSTANDARD
61
- internal const string _PythonDll = "__Internal" ;
62
- #else
63
- internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc ;
64
- #endif
36
+ static string _PythonDll ;
65
37
66
38
// set to true when python is finalizing
67
39
internal static object IsFinalizingLock = new object ( ) ;
@@ -2215,6 +2187,8 @@ internal static IntPtr GetBuiltins()
2215
2187
2216
2188
private static class Delegates
2217
2189
{
2190
+ static readonly ILibraryLoader libraryLoader = LibraryLoader . Get ( ) ;
2191
+
2218
2192
static Delegates ( )
2219
2193
{
2220
2194
PyDictProxy_New = ( delegate * unmanaged[ Cdecl] < IntPtr , IntPtr > ) GetFunctionByName ( nameof ( PyDictProxy_New ) , GetUnmanagedDll ( _PythonDll ) ) ;
@@ -2473,15 +2447,10 @@ static Delegates()
2473
2447
PyThreadState_SetAsyncExcLP64 = ( delegate * unmanaged[ Cdecl] < ulong , IntPtr , int > ) GetFunctionByName ( "PyThreadState_SetAsyncExc" , GetUnmanagedDll ( _PythonDll ) ) ;
2474
2448
}
2475
2449
2476
- static global ::System . IntPtr GetUnmanagedDll ( string libraryName )
2477
- {
2478
- throw new NotImplementedException ( ) ;
2479
- }
2450
+ static global ::System . IntPtr GetUnmanagedDll ( string libraryName ) => libraryLoader . Load ( libraryName ) ;
2480
2451
2481
2452
static global ::System . IntPtr GetFunctionByName ( string functionName , global ::System . IntPtr libraryHandle )
2482
- {
2483
- throw new NotImplementedException ( ) ;
2484
- }
2453
+ => libraryLoader . GetFunction ( libraryHandle , functionName ) ;
2485
2454
2486
2455
internal static delegate * unmanaged[ Cdecl] < IntPtr , IntPtr > PyDictProxy_New { get ; }
2487
2456
internal static delegate * unmanaged[ Cdecl] < IntPtr , void > Py_IncRef { get ; }
0 commit comments