Skip to content

Commit

Permalink
Switch boring from lazy_static to once_cell
Browse files Browse the repository at this point in the history
  • Loading branch information
nox authored and inikulin committed Aug 2, 2023
1 parent af5bb39 commit abfe2f7
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 19 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ fs_extra = "1.3.0"
fslock = "0.2"
bitflags = "1.0"
foreign-types = "0.5"
lazy_static = "1"
libc = "0.2"
hex = "0.4"
rusty-hook = "^0.11"
Expand Down
2 changes: 1 addition & 1 deletion boring/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pq-experimental = ["boring-sys/pq-experimental"]
[dependencies]
bitflags = { workspace = true }
foreign-types = { workspace = true }
lazy_static = { workspace = true }
once_cell = { workspace = true }
libc = { workspace = true }
boring-sys = { workspace = true }

Expand Down
2 changes: 0 additions & 2 deletions boring/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@
extern crate bitflags;
#[macro_use]
extern crate foreign_types;
#[macro_use]
extern crate lazy_static;
extern crate boring_sys as ffi;
extern crate libc;

Expand Down
12 changes: 6 additions & 6 deletions boring/src/ssl/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ where

let ssl = unsafe { SslRef::from_ptr_mut(ssl_ptr) };

let hint = if !hint.is_null() {
Some(unsafe { CStr::from_ptr(hint) }.to_bytes())
} else {
let hint = if hint.is_null() {
None
} else {
Some(unsafe { CStr::from_ptr(hint) }.to_bytes())
};

// Give the callback mutable slices into which it can write the identity and psk.
Expand Down Expand Up @@ -107,10 +107,10 @@ where

let ssl = unsafe { SslRef::from_ptr_mut(ssl) };

let identity = if !identity.is_null() {
Some(unsafe { CStr::from_ptr(identity) }.to_bytes())
} else {
let identity = if identity.is_null() {
None
} else {
Some(unsafe { CStr::from_ptr(identity) }.to_bytes())
};

// Give the callback mutable slices into which it can write the psk.
Expand Down
15 changes: 6 additions & 9 deletions boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
use crate::ffi;
use foreign_types::{ForeignType, ForeignTypeRef, Opaque};
use libc::{c_char, c_int, c_long, c_uchar, c_uint, c_void};
use once_cell::sync::Lazy;
use std::any::TypeId;
use std::cmp;
use std::collections::HashMap;
Expand Down Expand Up @@ -413,16 +414,12 @@ impl NameType {
}
}

lazy_static! {
static ref INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
static ref SSL_INDEXES: Mutex<HashMap<TypeId, c_int>> = Mutex::new(HashMap::new());
static ref SESSION_CTX_INDEX: Index<Ssl, SslContext> = Ssl::new_ex_index().unwrap();
}

static INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
static SSL_INDEXES: Lazy<Mutex<HashMap<TypeId, c_int>>> = Lazy::new(|| Mutex::new(HashMap::new()));
static SESSION_CTX_INDEX: Lazy<Index<Ssl, SslContext>> = Lazy::new(|| Ssl::new_ex_index().unwrap());
#[cfg(feature = "rpk")]
lazy_static! {
static ref RPK_FLAG_INDEX: Index<SslContext, bool> = SslContext::new_ex_index().unwrap();
}
static RPK_FLAG_INDEX: Lazy<Index<SslContext, bool>> =
Lazy::new(|| SslContext::new_ex_index().unwrap());

unsafe extern "C" fn free_data_box<T>(
_parent: *mut c_void,
Expand Down

0 comments on commit abfe2f7

Please sign in to comment.