-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use getrandom crate #62082
Use getrandom crate #62082
Changes from all commits
28ac843
621ef04
98be6f7
79ffb24
26a1108
66e799d
b6c7673
0056e1d
67ea529
e6d3ed3
568e492
560dd3e
0a63f37
7ac37e2
facdc28
5d0ae59
1fdf620
f94d928
dd9af37
4f3e2a0
93c89fe
f584f92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ profiler_builtins = { path = "../libprofiler_builtins", optional = true } | |
unwind = { path = "../libunwind" } | ||
hashbrown = { version = "0.4.0", features = ['rustc-dep-of-std'] } | ||
|
||
[target.'cfg(not(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown")))'.dependencies] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Due to the usage of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without an enabled |
||
getrandom = { version = "0.1.9", features = ['rustc-dep-of-std'] } | ||
|
||
[dependencies.backtrace] | ||
version = "0.3.34" | ||
default-features = false # don't use coresymbolication on OSX | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ use crate::fmt::{self, Debug}; | |
use crate::hash::{BuildHasher, Hash, Hasher, SipHasher13}; | ||
use crate::iter::{FromIterator, FusedIterator}; | ||
use crate::ops::Index; | ||
use crate::sys; | ||
|
||
/// A hash map implemented with quadratic probing and SIMD lookup. | ||
/// | ||
|
@@ -2445,13 +2444,25 @@ impl RandomState { | |
// iteration order allows a form of DOS attack. To counter that we | ||
// increment one of the seeds on every RandomState creation, giving | ||
// every corresponding HashMap a different iteration order. | ||
thread_local!(static KEYS: Cell<(u64, u64)> = { | ||
Cell::new(sys::hashmap_random_keys()) | ||
thread_local!(static KEYS: Cell<[u64; 2]> = { | ||
let mut buf = [0u8; 16]; | ||
// Use a constant seed on wasm32-unknown-unknown. | ||
// `cfg(target = "..")` does not work right now, see: | ||
// https://github.com/rust-lang/rust/issues/63217 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second part of this comment can be removed, it's fine to just say that on wasm32-unknown-unknown we skip this. |
||
if cfg!(not(all( | ||
target_arch = "wasm32", | ||
target_vendor = "unknown", | ||
target_os = "unknown", | ||
))) { | ||
getrandom::getrandom(&mut buf).unwrap(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On if false {
getrandom::getrandom(&mut buf).unwrap();
} ... so it does require the If you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But IIUC Cargo determines crates to be compiled only by looking at Cargo.toml, without taking crate code into account. So even if a dependency is not used, it will be still compiled, which in our case means a compilation error. I forgot that we can use #[cfg(..)]
getrandom::getrandom(&mut buf).unwrap(); I will replace those lines in the next commit. |
||
let n = u128::from_ne_bytes(buf); | ||
Cell::new([n as u64, (n >> 64) as u64]) | ||
}); | ||
|
||
KEYS.with(|keys| { | ||
let (k0, k1) = keys.get(); | ||
keys.set((k0.wrapping_add(1), k1)); | ||
let [k0, k1] = keys.get(); | ||
keys.set([k0.wrapping_add(1), k1]); | ||
RandomState { k0: k0, k1: k1 } | ||
}) | ||
} | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should update
Cargo.lock
here, as0.1.9
has been yanked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can wait until landing of VxWorks support.