| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -107,12 +107,27 @@ public static void GetPythonHomeDefault() | |||
| 107 | 107 | } | |
| 108 | 108 | ||
| 109 | 109 | [Test] | |
| 110 | - public void TestSetHome() | ||
| 110 | + public void SetPythonHome() | ||
| 111 | 111 | { | |
| 112 | - string homePath = @"C:\Python27\"; | ||
| 113 | - PythonEngine.PythonHome = homePath; | ||
| 112 | + var pythonHome = "/dummypath/"; | ||
| 113 | + | ||
| 114 | + PythonEngine.PythonHome = pythonHome; | ||
| 115 | + PythonEngine.Initialize(); | ||
| 116 | + | ||
| 117 | + Assert.AreEqual(pythonHome, PythonEngine.PythonHome); | ||
| 118 | + PythonEngine.Shutdown(); | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + [Test] | ||
| 122 | + public void SetPythonHomeTwice() | ||
| 123 | + { | ||
| 124 | + var pythonHome = "/dummypath/"; | ||
| 125 | + | ||
| 126 | + PythonEngine.PythonHome = "/dummypath2/"; | ||
| 127 | + PythonEngine.PythonHome = pythonHome; | ||
| 114 | 128 | PythonEngine.Initialize(); | |
| 115 | - Assert.AreEqual(PythonEngine.PythonHome, homePath); | ||
| 129 | + | ||
| 130 | + Assert.AreEqual(pythonHome, PythonEngine.PythonHome); | ||
| 116 | 131 | PythonEngine.Shutdown(); | |
| 117 | 132 | } | |
| 118 | 133 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ public class PythonEngine : IDisposable | |||
| 14 | 14 | { | |
| 15 | 15 | private static DelegateManager delegateManager; | |
| 16 | 16 | private static bool initialized; | |
| 17 | + private static IntPtr _pythonHome = IntPtr.Zero; | ||
| 17 | 18 | ||
| 18 | 19 | public PythonEngine() | |
| 19 | 20 | { | |
@@ -80,8 +81,12 @@ public static string PythonHome | |||
| 80 | 81 | } | |
| 81 | 82 | set | |
| 82 | 83 | { | |
| 83 | - IntPtr pythonHome = Marshal.StringToHGlobalAnsi(value); | ||
| 84 | - Runtime.Py_SetPythonHome(pythonHome); | ||
| 84 | + if (_pythonHome != IntPtr.Zero) | ||
| 85 | + { | ||
| 86 | + Marshal.FreeHGlobal(_pythonHome); | ||
| 87 | + } | ||
| 88 | + _pythonHome = Marshal.StringToHGlobalAnsi(value); | ||
| 89 | + Runtime.Py_SetPythonHome(_pythonHome); | ||
| 85 | 90 | } | |
| 86 | 91 | } | |
| 87 | 92 | ||
@@ -288,6 +293,8 @@ public static void Shutdown() | |||
| 288 | 293 | { | |
| 289 | 294 | if (initialized) | |
| 290 | 295 | { | |
| 296 | + Marshal.FreeHGlobal(_pythonHome); | ||
| 297 | + _pythonHome = IntPtr.Zero; | ||
| 291 | 298 | Runtime.Shutdown(); | |
| 292 | 299 | initialized = false; | |
| 293 | 300 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments