Skip to content

Commit 240c82a

Browse files
committed
Remove OnceCell
1 parent 9848925 commit 240c82a

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ version = "0.4.7"
1010

1111
[dependencies]
1212
arbitrary = "1"
13-
once_cell = "1"
1413

1514
[build-dependencies]
1615
cc = { version = "1.0", features = ["parallel"] }

src/lib.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![deny(missing_docs, missing_debug_implementations)]
1313

1414
pub use arbitrary;
15-
use once_cell::sync::OnceCell;
15+
use std::sync::OnceLock;
1616

1717
/// Indicates whether the input should be kept in the corpus or rejected. This
1818
/// should be returned by your fuzz target. If your fuzz target does not return
@@ -73,7 +73,10 @@ pub unsafe fn test_input_wrap(data: *const u8, size: usize) -> i32 {
7373
}
7474

7575
#[doc(hidden)]
76-
pub static RUST_LIBFUZZER_DEBUG_PATH: OnceCell<String> = OnceCell::new();
76+
pub fn rust_libfuzzer_debug_path() -> &'static Option<String> {
77+
static RUST_LIBFUZZER_DEBUG_PATH: OnceLock<Option<String>> = OnceLock::new();
78+
RUST_LIBFUZZER_DEBUG_PATH.get_or_init(|| std::env::var("RUST_LIBFUZZER_DEBUG_PATH").ok())
79+
}
7780

7881
#[doc(hidden)]
7982
#[export_name = "LLVMFuzzerInitialize"]
@@ -91,14 +94,6 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
9194
default_hook(panic_info);
9295
::std::process::abort();
9396
}));
94-
95-
// Initialize the `RUST_LIBFUZZER_DEBUG_PATH` cell with the path so it can be
96-
// reused with little overhead.
97-
if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") {
98-
RUST_LIBFUZZER_DEBUG_PATH
99-
.set(path)
100-
.expect("Since this is initialize it is only called once so can never fail");
101-
}
10297
0
10398
}
10499

@@ -213,7 +208,7 @@ macro_rules! fuzz_target {
213208
// `cargo fuzz`'s use!
214209

215210
// `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
216-
if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() {
211+
if let Some(path) = $crate::rust_libfuzzer_debug_path() {
217212
use std::io::Write;
218213
let mut file = std::fs::File::create(path)
219214
.expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");
@@ -278,7 +273,7 @@ macro_rules! fuzz_target {
278273
// `cargo fuzz`'s use!
279274

280275
// `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
281-
if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() {
276+
if let Some(path) = $crate::rust_libfuzzer_debug_path() {
282277
use std::io::Write;
283278
let mut file = std::fs::File::create(path)
284279
.expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");

0 commit comments

Comments
 (0)