| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 09f8281 commit 7ec9a6c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,16 +40,27 @@ public static void PlatformCache() | |||
| 40 | 40 | [Test] | |
| 41 | 41 | public static void Py_IsInitializedValue() | |
| 42 | 42 | { | |
| 43 | - if (Runtime.Runtime.Py_IsInitialized() == 1) | ||
| 43 | + IntPtr state = IntPtr.Zero; | ||
| 44 | + try | ||
| 44 | 45 | { | |
| 45 | - Runtime.Runtime.PyGILState_Ensure(); | ||
| 46 | + if (Runtime.Runtime.Py_IsInitialized() == 1) | ||
| 47 | + { | ||
| 48 | + state = Runtime.Runtime.PyGILState_Ensure(); | ||
| 49 | + } | ||
| 50 | + Runtime.Runtime.Py_Finalize(); | ||
| 51 | + Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); | ||
| 52 | + Runtime.Runtime.Py_Initialize(); | ||
| 53 | + Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized()); | ||
| 54 | + Runtime.Runtime.Py_Finalize(); | ||
| 55 | + Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); | ||
| 56 | + } | ||
| 57 | + finally | ||
| 58 | + { | ||
| 59 | + if(state != IntPtr.Zero) | ||
| 60 | + { | ||
| 61 | + Runtime.Runtime.PyGILState_Release(state); | ||
| 62 | + } | ||
| 46 | 63 | } | |
| 47 | - Runtime.Runtime.Py_Finalize(); | ||
| 48 | - Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); | ||
| 49 | - Runtime.Runtime.Py_Initialize(); | ||
| 50 | - Assert.AreEqual(1, Runtime.Runtime.Py_IsInitialized()); | ||
| 51 | - Runtime.Runtime.Py_Finalize(); | ||
| 52 | - Assert.AreEqual(0, Runtime.Runtime.Py_IsInitialized()); | ||
| 53 | 64 | } | |
| 54 | 65 | ||
| 55 | 66 | [Test] | |
| Back | FazBrowse Home | New Git URL |
0 commit comments