X Tutup
Skip to content

Commit f6de8ae

Browse files
author
linkliang
committed
revert to 1st version
1 parent 8f78699 commit f6de8ae

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

.DS_Store

8 KB
Binary file not shown.

src/.DS_Store

8 KB
Binary file not shown.

src/runtime/pythonengine.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public class PythonEngine : IDisposable
1717
private static IntPtr _pythonHome = IntPtr.Zero;
1818
private static IntPtr _programName = IntPtr.Zero;
1919
private static IntPtr _pythonPath = IntPtr.Zero;
20+
private static string _userPythonPath = "";
2021

2122
public PythonEngine()
2223
{
@@ -140,20 +141,13 @@ public static void Initialize()
140141
Initialize(setSysArgv: true);
141142
}
142143

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-
149144
public static void Initialize(string userPythonPath){
150-
IntPtr handle = dlopen(userPythonPath,0x8);
145+
_userPythonPath = userPythonPath;
151146
Console.WriteLine("Library loaded: " + userPythonPath);
152147
Initialize();
153-
dlclose(handle);
154148
}
155149

156-
public static void Initialize(bool setSysArgv = true, bool initSigs = false, string userPythonPath = "")
150+
public static void Initialize(bool setSysArgv = true, bool initSigs = false)
157151
{
158152
Initialize(Enumerable.Empty<string>(), setSysArgv: setSysArgv, initSigs: initSigs);
159153
}
@@ -168,7 +162,7 @@ public static void Initialize(bool setSysArgv = true, bool initSigs = false, str
168162
/// interpreter lock (GIL) to call this method.
169163
/// initSigs can be set to 1 to do default python signal configuration. This will override the way signals are handled by the application.
170164
/// </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)
172166
{
173167
if (!initialized)
174168
{
@@ -178,7 +172,7 @@ public static void Initialize(IEnumerable<string> args, bool setSysArgv = true,
178172
// during an initial "import clr", and the world ends shortly thereafter.
179173
// This is probably masking some bad mojo happening somewhere in Runtime.Initialize().
180174
delegateManager = new DelegateManager();
181-
Runtime.Initialize(initSigs);
175+
Runtime.Initialize(initSigs,_userPythonPath);
182176
initialized = true;
183177
Exceptions.Clear();
184178

src/runtime/runtime.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace Python.Runtime
99
{
1010
[SuppressUnmanagedCodeSecurity]
11-
internal static class NativeMethods
11+
public static class NativeMethods
1212
{
1313
#if MONO_LINUX || MONO_OSX
1414
#if NETSTANDARD
@@ -272,8 +272,12 @@ public enum MachineType
272272
/// <summary>
273273
/// Initialize the runtime...
274274
/// </summary>
275-
internal static void Initialize(bool initSigs = false)
275+
internal static void Initialize(bool initSigs = false, string userPythonPath = "")
276276
{
277+
if (userPythonPath.Length > 0){
278+
NativeMethods.dlopen(userPythonPath,0x8);
279+
Console.WriteLine("loaded library: " + userPythonPath);
280+
}
277281
if (Py_IsInitialized() == 0)
278282
{
279283
Py_InitializeEx(initSigs ? 1 : 0);

0 commit comments

Comments
 (0)
X Tutup