Skip to content

Commit 03f18ba

Browse files
authored
Use LazyLock for openssl probe (#607)
This switches the global static openssl probe to use LazyLock instead of Once. `static mut` refs are now an error in Rust 2024, and this is I believe the preferred method of doing something like this. LazyLock was added in 1.80 (released 2024-07-25), so the minimum version has to be bumped to that.
1 parent 9e900fe commit 03f18ba

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
target: x86_64-unknown-linux-gnu
2222
- build: ubuntu-lts
2323
os: ubuntu-24.04
24-
rust: 1.75
24+
rust: '1.80'
2525
docker: linux64
2626
target: x86_64-unknown-linux-gnu
2727
- build: x86_64-beta

src/easy/handler.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -676,22 +676,17 @@ impl<H: Handler> Easy2<H> {
676676

677677
#[cfg(need_openssl_probe)]
678678
fn ssl_configure(&mut self) {
679-
use std::sync::Once;
680-
681-
static mut PROBE: Option<::openssl_probe::ProbeResult> = None;
682-
static INIT: Once = Once::new();
679+
use std::sync::LazyLock;
683680

684681
// Probe for certificate stores the first time an easy handle is created,
685682
// and re-use the results for subsequent handles.
686-
INIT.call_once(|| unsafe {
687-
PROBE = Some(::openssl_probe::probe());
688-
});
689-
let probe = unsafe { PROBE.as_ref().unwrap() };
683+
static PROBE: LazyLock<openssl_probe::ProbeResult> =
684+
LazyLock::new(|| openssl_probe::probe());
690685

691-
if let Some(ref path) = probe.cert_file {
686+
if let Some(ref path) = PROBE.cert_file {
692687
let _ = self.cainfo(path);
693688
}
694-
if let Some(ref path) = probe.cert_dir {
689+
if let Some(ref path) = PROBE.cert_dir {
695690
let _ = self.capath(path);
696691
}
697692
}

0 commit comments

Comments
 (0)