From abfe2f798094d8b5855592aec8b5b90e3c2197e2 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Fri, 28 Jul 2023 11:35:46 +0200 Subject: [PATCH] Switch boring from lazy_static to once_cell --- Cargo.toml | 1 - boring/Cargo.toml | 2 +- boring/src/lib.rs | 2 -- boring/src/ssl/callbacks.rs | 12 ++++++------ boring/src/ssl/mod.rs | 15 ++++++--------- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b42a8ae1b..92f6be693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/boring/Cargo.toml b/boring/Cargo.toml index a6f546b47..34b0baaca 100644 --- a/boring/Cargo.toml +++ b/boring/Cargo.toml @@ -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 } diff --git a/boring/src/lib.rs b/boring/src/lib.rs index 348a346ae..b9d68fe75 100644 --- a/boring/src/lib.rs +++ b/boring/src/lib.rs @@ -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; diff --git a/boring/src/ssl/callbacks.rs b/boring/src/ssl/callbacks.rs index 1611681f9..b60a243ef 100644 --- a/boring/src/ssl/callbacks.rs +++ b/boring/src/ssl/callbacks.rs @@ -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. @@ -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. diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index 1d8129d43..67e16b181 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -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; @@ -413,16 +414,12 @@ impl NameType { } } -lazy_static! { - static ref INDEXES: Mutex> = Mutex::new(HashMap::new()); - static ref SSL_INDEXES: Mutex> = Mutex::new(HashMap::new()); - static ref SESSION_CTX_INDEX: Index = Ssl::new_ex_index().unwrap(); -} - +static INDEXES: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); +static SSL_INDEXES: Lazy>> = Lazy::new(|| Mutex::new(HashMap::new())); +static SESSION_CTX_INDEX: Lazy> = Lazy::new(|| Ssl::new_ex_index().unwrap()); #[cfg(feature = "rpk")] -lazy_static! { - static ref RPK_FLAG_INDEX: Index = SslContext::new_ex_index().unwrap(); -} +static RPK_FLAG_INDEX: Lazy> = + Lazy::new(|| SslContext::new_ex_index().unwrap()); unsafe extern "C" fn free_data_box( _parent: *mut c_void,