1
1
#![ feature( concat_idents) ]
2
2
3
+ use parking_lot:: { lock_api:: RawMutex as _RawMutex, RawMutex } ;
3
4
use pyo3:: ffi:: * ;
4
5
use pyo3:: prelude:: * ;
5
6
use pyo3:: types:: IntoPyDict ;
@@ -56,19 +57,14 @@ macro_rules! assert_check_only {
56
57
57
58
// Because of the relase pool unsoundness reported in https://github.com/PyO3/pyo3/issues/756,
58
59
// 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 ;
66
62
67
63
#[ test]
68
64
fn test_date_check ( ) {
65
+ let _lock = MUTEX . lock ( ) ;
69
66
let gil = Python :: acquire_gil ( ) ;
70
67
let py = gil. python ( ) ;
71
- lock ! ( ) ;
72
68
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "date" , "2018, 1, 1" ) . unwrap ( ) ;
73
69
74
70
assert_check_exact ! ( PyDate_Check , obj) ;
@@ -78,9 +74,9 @@ fn test_date_check() {
78
74
79
75
#[ test]
80
76
fn test_time_check ( ) {
77
+ let _lock = MUTEX . lock ( ) ;
81
78
let gil = Python :: acquire_gil ( ) ;
82
79
let py = gil. python ( ) ;
83
- lock ! ( ) ;
84
80
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "time" , "12, 30, 15" ) . unwrap ( ) ;
85
81
86
82
assert_check_exact ! ( PyTime_Check , obj) ;
@@ -90,9 +86,9 @@ fn test_time_check() {
90
86
91
87
#[ test]
92
88
fn test_datetime_check ( ) {
89
+ let _lock = MUTEX . lock ( ) ;
93
90
let gil = Python :: acquire_gil ( ) ;
94
91
let py = gil. python ( ) ;
95
- lock ! ( ) ;
96
92
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "datetime" , "2018, 1, 1, 13, 30, 15" )
97
93
. map_err ( |e| e. print ( py) )
98
94
. unwrap ( ) ;
@@ -105,9 +101,9 @@ fn test_datetime_check() {
105
101
106
102
#[ test]
107
103
fn test_delta_check ( ) {
104
+ let _lock = MUTEX . lock ( ) ;
108
105
let gil = Python :: acquire_gil ( ) ;
109
106
let py = gil. python ( ) ;
110
- lock ! ( ) ;
111
107
let ( obj, sub_obj, sub_sub_obj) = _get_subclasses ( & py, "timedelta" , "1, -3" ) . unwrap ( ) ;
112
108
113
109
assert_check_exact ! ( PyDelta_Check , obj) ;
@@ -120,9 +116,9 @@ fn test_datetime_utc() {
120
116
use assert_approx_eq:: assert_approx_eq;
121
117
use pyo3:: types:: PyDateTime ;
122
118
119
+ let _lock = MUTEX . lock ( ) ;
123
120
let gil = Python :: acquire_gil ( ) ;
124
121
let py = gil. python ( ) ;
125
- lock ! ( ) ;
126
122
let datetime = py. import ( "datetime" ) . map_err ( |e| e. print ( py) ) . unwrap ( ) ;
127
123
let timezone = datetime. get ( "timezone" ) . unwrap ( ) ;
128
124
let utc = timezone. getattr ( "utc" ) . unwrap ( ) . to_object ( py) ;
0 commit comments