File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,16 +40,27 @@ public static void PlatformCache()
4040 [ Test ]
4141 public static void Py_IsInitializedValue ( )
4242 {
43- if ( Runtime . Runtime . Py_IsInitialized ( ) == 1 )
43+ IntPtr state = IntPtr . Zero ;
44+ try
4445 {
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+ }
4663 }
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 ( ) ) ;
5364 }
5465
5566 [ Test ]
You can’t perform that action at this time.
0 commit comments