@@ -52,7 +52,7 @@ use std::ptr::NonNull;
52
52
53
53
use pyo3:: {
54
54
exceptions:: PyRuntimeError ,
55
- ffi,
55
+ ffi, intern ,
56
56
prelude:: * ,
57
57
sync:: GILOnceCell ,
58
58
types:: { DerefToPyAny , PyCapsule , PyType } ,
@@ -100,18 +100,21 @@ pub trait PyBitGeneratorMethods {
100
100
101
101
impl < ' py > PyBitGeneratorMethods for Bound < ' py , PyBitGenerator > {
102
102
fn lock ( & self ) -> PyResult < PyBitGeneratorGuard > {
103
- let capsule = self . getattr ( "capsule" ) ?. downcast_into :: < PyCapsule > ( ) ?;
104
- let lock = self . getattr ( "lock" ) ?;
103
+ let py = self . py ( ) ;
104
+ let capsule = self
105
+ . getattr ( intern ! ( py, "capsule" ) ) ?
106
+ . downcast_into :: < PyCapsule > ( ) ?;
107
+ let lock = self . getattr ( intern ! ( py, "lock" ) ) ?;
105
108
// we’re holding the GIL, so there’s no race condition checking the lock and acquiring it later.
106
- if lock. call_method0 ( "locked" ) ?. extract ( ) ? {
109
+ if lock. call_method0 ( intern ! ( py , "locked" ) ) ?. extract ( ) ? {
107
110
return Err ( PyRuntimeError :: new_err ( "BitGenerator is already locked" ) ) ;
108
111
}
109
- lock. call_method0 ( "acquire" ) ?;
112
+ lock. call_method0 ( intern ! ( py , "acquire" ) ) ?;
110
113
111
114
assert_eq ! ( capsule. name( ) ?, Some ( ffi:: c_str!( "BitGenerator" ) ) ) ;
112
115
let ptr = capsule. pointer ( ) as * mut bitgen_t ;
113
116
let Some ( non_null) = NonNull :: new ( ptr) else {
114
- lock. call_method0 ( "release" ) ?;
117
+ lock. call_method0 ( intern ! ( py , "release" ) ) ?;
115
118
return Err ( PyRuntimeError :: new_err ( "Invalid BitGenerator capsule" ) ) ;
116
119
} ;
117
120
Ok ( PyBitGeneratorGuard {
@@ -146,7 +149,7 @@ impl Drop for PyBitGeneratorGuard {
146
149
fn drop ( & mut self ) {
147
150
// ignore errors. This includes when `try_release` was called manually.
148
151
let _ = Python :: with_gil ( |py| -> PyResult < _ > {
149
- self . lock . bind ( py) . call_method0 ( "release" ) ?;
152
+ self . lock . bind ( py) . call_method0 ( intern ! ( py , "release" ) ) ?;
150
153
Ok ( ( ) )
151
154
} ) ;
152
155
}
@@ -157,7 +160,7 @@ impl Drop for PyBitGeneratorGuard {
157
160
impl < ' py > PyBitGeneratorGuard {
158
161
/// Release the lock, allowing for checking for errors.
159
162
pub fn release ( self , py : Python < ' py > ) -> PyResult < ( ) > {
160
- self . lock . bind ( py) . call_method0 ( "release" ) ?;
163
+ self . lock . bind ( py) . call_method0 ( intern ! ( py , "release" ) ) ?;
161
164
Ok ( ( ) )
162
165
}
163
166
0 commit comments