@@ -2,7 +2,7 @@ use std::{
2
2
ffi:: CStr ,
3
3
fmt, ptr,
4
4
str:: Utf8Error ,
5
- sync:: { Mutex , OnceLock , RwLock } ,
5
+ sync:: { Mutex , OnceLock } ,
6
6
} ;
7
7
8
8
use self :: {
@@ -180,7 +180,7 @@ cfg_if::cfg_if! {
180
180
/// ```
181
181
#[ inline]
182
182
pub fn init ( ) -> Gpgme {
183
- static TOKEN : OnceLock < ( & str , RwLock < ( ) > ) > = OnceLock :: new ( ) ;
183
+ static TOKEN : OnceLock < & str > = OnceLock :: new ( ) ;
184
184
let token = TOKEN . get_or_init ( || unsafe {
185
185
let offset = memoffset:: offset_of!( ffi:: _gpgme_signature, validity) ;
186
186
@@ -189,24 +189,17 @@ pub fn init() -> Gpgme {
189
189
!result. is_null( ) ,
190
190
"the library linked is not the correct version"
191
191
) ;
192
- (
193
- CStr :: from_ptr ( result)
194
- . to_str ( )
195
- . expect ( "gpgme version string is not valid utf-8" ) ,
196
- RwLock :: default ( ) ,
197
- )
192
+ CStr :: from_ptr ( result)
193
+ . to_str ( )
194
+ . expect ( "gpgme version string is not valid utf-8" )
198
195
} ) ;
199
- Gpgme {
200
- version : token. 0 ,
201
- engine_lock : & token. 1 ,
202
- }
196
+ Gpgme { version : token }
203
197
}
204
198
205
199
/// A type for managing the library's configuration.
206
200
#[ derive( Debug , Clone ) ]
207
201
pub struct Gpgme {
208
202
version : & ' static str ,
209
- engine_lock : & ' static RwLock < ( ) > ,
210
203
}
211
204
212
205
impl Gpgme {
@@ -289,31 +282,19 @@ impl Gpgme {
289
282
/// [`gpgme_get_engine_info`](https://www.gnupg.org/documentation/manuals/gpgme/Engine-Information.html#index-gpgme_005fget_005fengine_005finfo)
290
283
#[ inline]
291
284
pub fn engine_info ( & self ) -> Result < EngineInfoGuard > {
292
- EngineInfoGuard :: new ( self . engine_lock )
293
- }
294
-
295
- // Requires the engine_lock to be held by the current thread when called
296
- unsafe fn get_engine_info ( & self , proto : Protocol ) -> ffi:: gpgme_engine_info_t {
297
- let mut info = ptr:: null_mut ( ) ;
298
- assert_eq ! ( ffi:: gpgme_get_engine_info( & mut info) , 0 ) ;
299
- while !info. is_null ( ) && ( ( * info) . protocol != proto. raw ( ) ) {
300
- info = ( * info) . next ;
301
- }
302
- info
285
+ EngineInfoGuard :: new ( )
303
286
}
304
287
305
288
#[ inline]
306
289
pub fn set_engine_path ( & self , proto : Protocol , path : impl CStrArgument ) -> Result < ( ) > {
307
290
let path = path. into_cstr ( ) ;
308
- let _lock = self
309
- . engine_lock
310
- . write ( )
311
- . expect ( "engine info lock was poisoned" ) ;
312
291
unsafe {
313
292
let home_dir = self
314
- . get_engine_info ( proto)
293
+ . engine_info ( ) ?
294
+ . get ( proto)
315
295
. as_ref ( )
316
- . map_or ( ptr:: null ( ) , |x| x. home_dir ) ;
296
+ . and_then ( |x| x. home_dir_raw ( ) )
297
+ . map_or ( ptr:: null ( ) , |x| x. as_ptr ( ) ) ;
317
298
convert_err ( ffi:: gpgme_set_engine_info (
318
299
proto. raw ( ) ,
319
300
path. as_ref ( ) . as_ptr ( ) ,
@@ -326,15 +307,13 @@ impl Gpgme {
326
307
#[ inline]
327
308
pub fn set_engine_home_dir ( & self , proto : Protocol , home_dir : impl CStrArgument ) -> Result < ( ) > {
328
309
let home_dir = home_dir. into_cstr ( ) ;
329
- let _lock = self
330
- . engine_lock
331
- . write ( )
332
- . expect ( "engine info lock was poisoned" ) ;
333
310
unsafe {
334
311
let path = self
335
- . get_engine_info ( proto)
312
+ . engine_info ( ) ?
313
+ . get ( proto)
336
314
. as_ref ( )
337
- . map_or ( ptr:: null ( ) , |x| x. file_name ) ;
315
+ . and_then ( |x| x. path_raw ( ) )
316
+ . map_or ( ptr:: null ( ) , |x| x. as_ptr ( ) ) ;
338
317
convert_err ( ffi:: gpgme_set_engine_info (
339
318
proto. raw ( ) ,
340
319
path,
@@ -360,10 +339,6 @@ impl Gpgme {
360
339
. as_ref ( )
361
340
. map_or ( ptr:: null ( ) , |s| s. as_ref ( ) . as_ptr ( ) ) ;
362
341
unsafe {
363
- let _lock = self
364
- . engine_lock
365
- . write ( )
366
- . expect ( "engine info lock was poisoned" ) ;
367
342
convert_err ( ffi:: gpgme_set_engine_info ( proto. raw ( ) , path, home_dir) ) ?;
368
343
}
369
344
Ok ( ( ) )
0 commit comments