Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove once_cell #120

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ version = "0.4.7"

[dependencies]
arbitrary = "1"
once_cell = "1"

[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
Expand Down
19 changes: 7 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#![deny(missing_docs, missing_debug_implementations)]

pub use arbitrary;
use once_cell::sync::OnceCell;
use std::sync::OnceLock;

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

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

#[doc(hidden)]
#[export_name = "LLVMFuzzerInitialize"]
Expand All @@ -91,14 +94,6 @@ pub fn initialize(_argc: *const isize, _argv: *const *const *const u8) -> isize
default_hook(panic_info);
::std::process::abort();
}));

// Initialize the `RUST_LIBFUZZER_DEBUG_PATH` cell with the path so it can be
// reused with little overhead.
if let Ok(path) = std::env::var("RUST_LIBFUZZER_DEBUG_PATH") {
RUST_LIBFUZZER_DEBUG_PATH
.set(path)
.expect("Since this is initialize it is only called once so can never fail");
}
0
}

Expand Down Expand Up @@ -213,7 +208,7 @@ macro_rules! fuzz_target {
// `cargo fuzz`'s use!

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

// `RUST_LIBFUZZER_DEBUG_PATH` is set in initialization.
if let Some(path) = $crate::RUST_LIBFUZZER_DEBUG_PATH.get() {
if let Some(path) = $crate::rust_libfuzzer_debug_path() {
use std::io::Write;
let mut file = std::fs::File::create(path)
.expect("failed to create `RUST_LIBFUZZER_DEBUG_PATH` file");
Expand Down