11#![ feature( concat_idents) ]
22
3+ use parking_lot:: { lock_api:: RawMutex as _RawMutex, RawMutex } ;
34use pyo3:: ffi:: * ;
45use pyo3:: prelude:: * ;
56use pyo3:: types:: IntoPyDict ;
@@ -56,19 +57,14 @@ macro_rules! assert_check_only {
5657
5758// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
5859// we need to stop other threads before calling `py.import()`.
59- // TODO(kngwyu): Remove this macro
60- macro_rules! lock {
61- ( ) => {
62- let _mutex = std:: sync:: Mutex :: new( ( ) ) ;
63- let _lock = _mutex. lock( ) . unwrap( ) ;
64- } ;
65- }
60+ // TODO(kngwyu): Remove this variable
61+ const MUTEX : RawMutex = RawMutex :: INIT ;
6662
6763#[ test]
6864fn test_date_check ( ) {
65+ let _lock = MUTEX . lock ( ) ;
6966 let gil = Python :: acquire_gil ( ) ;
7067 let py = gil. python ( ) ;
71- lock ! ( ) ;
7268 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "date" , "2018, 1, 1" ) . unwrap ( ) ;
7369
7470 assert_check_exact ! ( PyDate_Check , obj) ;
@@ -78,9 +74,9 @@ fn test_date_check() {
7874
7975#[ test]
8076fn test_time_check ( ) {
77+ let _lock = MUTEX . lock ( ) ;
8178 let gil = Python :: acquire_gil ( ) ;
8279 let py = gil. python ( ) ;
83- lock ! ( ) ;
8480 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "time" , "12, 30, 15" ) . unwrap ( ) ;
8581
8682 assert_check_exact ! ( PyTime_Check , obj) ;
@@ -90,9 +86,9 @@ fn test_time_check() {
9086
9187#[ test]
9288fn test_datetime_check ( ) {
89+ let _lock = MUTEX . lock ( ) ;
9390 let gil = Python :: acquire_gil ( ) ;
9491 let py = gil. python ( ) ;
95- lock ! ( ) ;
9692 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "datetime" , "2018, 1, 1, 13, 30, 15" )
9793 . map_err ( |e| e. print ( py) )
9894 . unwrap ( ) ;
@@ -105,9 +101,9 @@ fn test_datetime_check() {
105101
106102#[ test]
107103fn test_delta_check ( ) {
104+ let _lock = MUTEX . lock ( ) ;
108105 let gil = Python :: acquire_gil ( ) ;
109106 let py = gil. python ( ) ;
110- lock ! ( ) ;
111107 let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "timedelta" , "1, -3" ) . unwrap ( ) ;
112108
113109 assert_check_exact ! ( PyDelta_Check , obj) ;
@@ -120,9 +116,9 @@ fn test_datetime_utc() {
120116 use assert_approx_eq:: assert_approx_eq;
121117 use pyo3:: types:: PyDateTime ;
122118
119+ let _lock = MUTEX . lock ( ) ;
123120 let gil = Python :: acquire_gil ( ) ;
124121 let py = gil. python ( ) ;
125- lock ! ( ) ;
126122 let datetime = py. import ( "datetime" ) . map_err ( |e| e. print ( py) ) . unwrap ( ) ;
127123 let timezone = datetime. get ( "timezone" ) . unwrap ( ) ;
128124 let utc = timezone. getattr ( "utc" ) . unwrap ( ) . to_object ( py) ;
0 commit comments