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

Replace lazy_static and spin dependencies with conquer-once. #924

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,13 @@ name = "ring"
untrusted = { version = "0.7.0" }

[target.'cfg(all(any(target_arch = "aarch64", target_arch = "arm", target_arch = "x86", target_arch = "x86_64"), not(target_os = "ios")))'.dependencies]
spin = { version = "0.5.2", default-features = false }

conquer-once = { version = "0.1.2", default-features = false }

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies]
libc = { version = "0.2.48", default-features = false }

[target.'cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux", target_os = "netbsd", target_os = "openbsd", target_os = "solaris"))'.dependencies]
lazy_static = { version = "1.3", default-features = false, optional = true }
conquer-once = { version = "0.1.2", default-features = false, features = ["std"], optional = true }

[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown", target_env = ""))'.dependencies]
web-sys = { version = "0.3.25", default-features = false, features = ["Crypto", "Window"] }
Expand All @@ -333,7 +332,7 @@ cc = { version = "1.0.37", default-features = false }
# These features are documented in the top-level module's documentation.
default = ["alloc", "dev_urandom_fallback"]
alloc = []
dev_urandom_fallback = ["lazy_static"]
dev_urandom_fallback = ["conquer-once"]
internal_benches = []
slow_tests = []
std = ["alloc"]
Expand Down
4 changes: 2 additions & 2 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub(crate) fn features() -> Features {
not(target_os = "ios")
))]
{
static INIT: spin::Once<()> = spin::Once::new();
let () = INIT.call_once(|| {
static INIT: conquer_once::spin::Once = conquer_once::spin::Once::new();
let () = INIT.init_once(|| {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
{
extern "C" {
Expand Down
28 changes: 10 additions & 18 deletions src/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,14 @@ mod sysrand_or_urandom {

#[inline]
pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> {
use lazy_static::lazy_static;

lazy_static! {
static ref MECHANISM: Mechanism = {
let mut dummy = [0u8; 1];
if super::sysrand_chunk::chunk(&mut dummy[..]).is_err() {
Mechanism::DevURandom
} else {
Mechanism::Sysrand
}
};
}
static MECHANISM: conquer_once::Lazy<Mechanism> = conquer_once::Lazy::new(|| {
let mut dummy = [0u8; 1];
if super::sysrand_chunk::chunk(&mut dummy[..]).is_err() {
Mechanism::DevURandom
} else {
Mechanism::Sysrand
}
});

match *MECHANISM {
Mechanism::Sysrand => super::sysrand::fill(dest),
Expand All @@ -366,12 +362,8 @@ mod urandom {
pub fn fill(dest: &mut [u8]) -> Result<(), error::Unspecified> {
extern crate std;

use lazy_static::lazy_static;

lazy_static! {
static ref FILE: Result<std::fs::File, std::io::Error> =
std::fs::File::open("/dev/urandom");
}
static FILE: conquer_once::Lazy<Result<std::fs::File, std::io::Error>> =
conquer_once::Lazy::new(|| std::fs::File::open("/dev/urandom"));

match *FILE {
Ok(ref file) => {
Expand Down