| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f78699 commit f6de8ae
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,7 @@ public class PythonEngine : IDisposable | |||
| 17 | 17 | private static IntPtr _pythonHome = IntPtr.Zero; | |
| 18 | 18 | private static IntPtr _programName = IntPtr.Zero; | |
| 19 | 19 | private static IntPtr _pythonPath = IntPtr.Zero; | |
| 20 | + private static string _userPythonPath = ""; | ||
| 20 | 21 | ||
| 21 | 22 | public PythonEngine() | |
| 22 | 23 | { | |
@@ -140,20 +141,13 @@ public static void Initialize() | |||
| 140 | 141 | Initialize(setSysArgv: true); | |
| 141 | 142 | } | |
| 142 | 143 | ||
| 143 | - [DllImport("/usr/lib/libSystem.dylib", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] | ||
| 144 | - public static extern IntPtr dlopen(String fileName, int flags); | ||
| 145 | - | ||
| 146 | - [DllImport("/usr/lib/libSystem.dylib", CallingConvention = CallingConvention.Cdecl)] | ||
| 147 | - private static extern int dlclose(IntPtr handle); | ||
| 148 | - | ||
| 149 | 144 | public static void Initialize(string userPythonPath){ | |
| 150 | - IntPtr handle = dlopen(userPythonPath,0x8); | ||
| 145 | + _userPythonPath = userPythonPath; | ||
| 151 | 146 | Console.WriteLine("Library loaded: " + userPythonPath); | |
| 152 | 147 | Initialize(); | |
| 153 | - dlclose(handle); | ||
| 154 | 148 | } | |
| 155 | 149 | ||
| 156 | - public static void Initialize(bool setSysArgv = true, bool initSigs = false, string userPythonPath = "") | ||
| 150 | + public static void Initialize(bool setSysArgv = true, bool initSigs = false) | ||
| 157 | 151 | { | |
| 158 | 152 | Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv, initSigs: initSigs); | |
| 159 | 153 | } | |
@@ -168,7 +162,7 @@ public static void Initialize(bool setSysArgv = true, bool initSigs = false, str | |||
| 168 | 162 | /// interpreter lock (GIL) to call this method. | |
| 169 | 163 | /// initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application. | |
| 170 | 164 | /// </remarks> | |
| 171 | - public static void Initialize(IEnumerable<string> args, bool setSysArgv = true, bool initSigs = false, string userPythonPath = "") | ||
| 165 | + public static void Initialize(IEnumerable<string> args, bool setSysArgv = true, bool initSigs = false) | ||
| 172 | 166 | { | |
| 173 | 167 | if (!initialized) | |
| 174 | 168 | { | |
@@ -178,7 +172,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true, | |||
| 178 | 172 | // during an initial "import clr", and the world ends shortly thereafter. | |
| 179 | 173 | // This is probably masking some bad mojo happening somewhere in Runtime.Initialize(). | |
| 180 | 174 | delegateManager = new DelegateManager(); | |
| 181 | - Runtime.Initialize(initSigs); | ||
| 175 | + Runtime.Initialize(initSigs,_userPythonPath); | ||
| 182 | 176 | initialized = true; | |
| 183 | 177 | Exceptions.Clear(); | |
| 184 | 178 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | namespace Python.Runtime | |
| 9 | 9 | { | |
| 10 | 10 | [SuppressUnmanagedCodeSecurity] | |
| 11 | - internal static class NativeMethods | ||
| 11 | + public static class NativeMethods | ||
| 12 | 12 | { | |
| 13 | 13 | #if MONO_LINUX || MONO_OSX | |
| 14 | 14 | #if NETSTANDARD | |
@@ -272,8 +272,12 @@ public enum MachineType | |||
| 272 | 272 | /// <summary> | |
| 273 | 273 | /// Initialize the runtime... | |
| 274 | 274 | /// </summary> | |
| 275 | - internal static void Initialize(bool initSigs = false) | ||
| 275 | + internal static void Initialize(bool initSigs = false, string userPythonPath = "") | ||
| 276 | 276 | { | |
| 277 | + if (userPythonPath.Length > 0){ | ||
| 278 | + NativeMethods.dlopen(userPythonPath,0x8); | ||
| 279 | + Console.WriteLine("loaded library: " + userPythonPath); | ||
| 280 | + } | ||
| 277 | 281 | if (Py_IsInitialized() == 0) | |
| 278 | 282 | { | |
| 279 | 283 | Py_InitializeEx(initSigs ? 1 : 0); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments