Update rand to 0.9

This commit is contained in:
Noa
2025-02-17 11:48:50 -06:00
committed by Jeong, YunWon
parent a71c16f8cb
commit fa2acd7cde
15 changed files with 50 additions and 49 deletions

View File

@@ -379,7 +379,8 @@ jobs:
with: { wabt-version: "1.0.30" }
- name: check wasm32-unknown without js
run: |
cargo build --release --manifest-path wasm/wasm-unknown-test/Cargo.toml --target wasm32-unknown-unknown --verbose
cd wasm/wasm-unknown-test
cargo build --release --verbose
if wasm-objdump -xj Import target/wasm32-unknown-unknown/release/wasm_unknown_test.wasm; then
echo "ERROR: wasm32-unknown module expects imports from the host environment" >2
fi

20
Cargo.lock generated
View File

@@ -808,8 +808,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43a49c392881ce6d5c3b8cb70f98717b7c07aabbdff06687b9030dbfbe2725f8"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi 0.13.3+wasi-0.2.2",
"wasm-bindgen",
"windows-targets 0.52.6",
]
@@ -1306,11 +1308,11 @@ dependencies = [
[[package]]
name = "mt19937"
version = "2.0.1"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12ca7f22ed370d5991a9caec16a83187e865bc8a532f889670337d5a5689e3a1"
checksum = "df7151a832e54d2d6b2c827a20e5bcdd80359281cd2c354e725d4b82e7c471de"
dependencies = [
"rand_core 0.6.4",
"rand_core 0.9.0",
]
[[package]]
@@ -2007,7 +2009,7 @@ dependencies = [
"once_cell",
"parking_lot",
"radium",
"rand 0.8.5",
"rand 0.9.0",
"rustpython-format",
"siphasher 0.3.11",
"volatile",
@@ -2216,8 +2218,7 @@ dependencies = [
"parking_lot",
"paste",
"puruspe",
"rand 0.8.5",
"rand_core 0.6.4",
"rand 0.9.0",
"rustix",
"rustpython-common",
"rustpython-derive",
@@ -2262,7 +2263,7 @@ dependencies = [
"exitcode",
"flame",
"flamer",
"getrandom 0.2.15",
"getrandom 0.3.1",
"glob",
"half 2.4.1",
"hex",
@@ -2285,7 +2286,7 @@ dependencies = [
"optional",
"parking_lot",
"paste",
"rand 0.8.5",
"rand 0.9.0",
"result-like",
"rustc_version",
"rustix",
@@ -2329,6 +2330,7 @@ name = "rustpython_wasm"
version = "0.4.0"
dependencies = [
"console_error_panic_hook",
"getrandom 0.2.15",
"js-sys",
"rustpython-common",
"rustpython-parser",
@@ -3000,8 +3002,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ced87ca4be083373936a67f8de945faa23b6b42384bd5b64434850802c6dccd0"
dependencies = [
"atomic",
"getrandom 0.3.1",
"rand 0.9.0",
]
[[package]]

View File

@@ -146,7 +146,7 @@ cfg-if = "1.0"
chrono = "0.4.39"
crossbeam-utils = "0.8.21"
flame = "0.2.2"
getrandom = "0.2.15"
getrandom = "0.3"
glob = "0.3"
hex = "0.4.3"
indexmap = { version = "2.2.6", features = ["std"] }
@@ -168,7 +168,7 @@ num_enum = { version = "0.7", default-features = false }
once_cell = "1.20.3"
parking_lot = "0.12.3"
paste = "1.0.15"
rand = "0.8.5"
rand = "0.9"
rustix = { version = "0.38", features = ["event"] }
rustyline = "15.0.0"
serde = { version = "1.0.133", default-features = false }

View File

@@ -37,11 +37,11 @@ impl BuildHasher for HashSecret {
}
}
impl rand::distributions::Distribution<HashSecret> for rand::distributions::Standard {
impl rand::distr::Distribution<HashSecret> for rand::distr::StandardUniform {
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> HashSecret {
HashSecret {
k0: rng.gen(),
k1: rng.gen(),
k0: rng.random(),
k1: rng.random(),
}
}
}

View File

@@ -54,8 +54,7 @@ xml-rs = "0.8.14"
# random
rand = { workspace = true }
rand_core = "0.6.4"
mt19937 = "2.0.1"
mt19937 = "3.1"
# Crypto:
digest = "0.10.3"
@@ -88,7 +87,7 @@ bzip2 = { version = "0.4", optional = true }
# uuid
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32", target_os = "redox")))'.dependencies]
mac_address = "1.1.3"
uuid = { version = "1.1.2", features = ["v1", "fast-rng"] }
uuid = { version = "1.1.2", features = ["v1"] }
# mmap
[target.'cfg(all(unix, not(target_arch = "wasm32")))'.dependencies]

View File

@@ -23,7 +23,7 @@ mod _random {
impl Default for PyRng {
fn default() -> Self {
PyRng::Std(Box::new(StdRng::from_entropy()))
PyRng::Std(Box::new(StdRng::from_os_rng()))
}
}
@@ -46,12 +46,6 @@ mod _random {
Self::MT(m) => m.fill_bytes(dest),
}
}
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
match self {
Self::Std(s) => s.try_fill_bytes(dest),
Self::MT(m) => m.try_fill_bytes(dest),
}
}
}
#[pyattr]

View File

@@ -5,33 +5,19 @@ mod _uuid {
use crate::{builtins::PyNone, vm::VirtualMachine};
use mac_address::get_mac_address;
use once_cell::sync::OnceCell;
use rand::Rng;
use std::time::{Duration, SystemTime};
use uuid::{
v1::{Context, Timestamp},
Uuid,
};
use uuid::{timestamp::Timestamp, Context, Uuid};
fn get_node_id() -> [u8; 6] {
match get_mac_address() {
Ok(Some(_ma)) => get_mac_address().unwrap().unwrap().bytes(),
_ => rand::thread_rng().gen::<[u8; 6]>(),
_ => rand::random::<[u8; 6]>(),
}
}
pub fn now_unix_duration() -> Duration {
use std::time::UNIX_EPOCH;
let now = SystemTime::now();
now.duration_since(UNIX_EPOCH)
.expect("SystemTime before UNIX EPOCH!")
}
#[pyfunction]
fn generate_time_safe() -> (Vec<u8>, PyNone) {
static CONTEXT: Context = Context::new(0);
let now = now_unix_duration();
let ts = Timestamp::from_unix(&CONTEXT, now.as_secs(), now.subsec_nanos());
let ts = Timestamp::now(&CONTEXT);
static NODE_ID: OnceCell<[u8; 6]> = OnceCell::new();
let unique_node_id = NODE_ID.get_or_init(get_node_id);

View File

@@ -23,7 +23,7 @@ ast = ["rustpython-ast"]
codegen = ["rustpython-codegen", "ast"]
parser = ["rustpython-parser", "ast"]
serde = ["dep:serde"]
wasmbind = ["chrono/wasmbind", "getrandom/js", "wasm-bindgen"]
wasmbind = ["chrono/wasmbind", "getrandom/wasm_js", "wasm-bindgen"]
[dependencies]
rustpython-compiler = { workspace = true, optional = true }
@@ -145,7 +145,7 @@ features = [
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
wasm-bindgen = { workspace = true, optional = true }
getrandom = { workspace = true, features = ["custom"] }
getrandom = { workspace = true }
[build-dependencies]
glob = { workspace = true }

View File

@@ -8,7 +8,6 @@ use crate::{
vm::{thread, VirtualMachine},
AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
};
use rand::Rng;
pub(crate) fn init_importlib_base(vm: &mut VirtualMachine) -> PyResult<PyObjectRef> {
flame_guard!("init importlib");
@@ -50,7 +49,7 @@ pub(crate) fn init_importlib_package(vm: &VirtualMachine, importlib: PyObjectRef
let mut magic = get_git_revision().into_bytes();
magic.truncate(4);
if magic.len() != 4 {
magic = rand::thread_rng().gen::<[u8; 4]>().to_vec();
magic = rand::random::<[u8; 4]>().to_vec();
}
let magic: PyObjectRef = vm.ctx.new_bytes(magic).into();
importlib_external.set_attr("MAGIC_NUMBER", magic, vm)?;

View File

@@ -978,7 +978,7 @@ pub(super) mod _os {
return Err(vm.new_value_error("negative argument not allowed".to_owned()));
}
let mut buf = vec![0u8; size as usize];
getrandom::getrandom(&mut buf).map_err(|e| match e.raw_os_error() {
getrandom::fill(&mut buf).map_err(|e| match e.raw_os_error() {
Some(errno) => io::Error::from_raw_os_error(errno).into_pyexception(vm),
None => vm.new_os_error("Getting random failed".to_owned()),
})?;

View File

@@ -0,0 +1,5 @@
[build]
target = "wasm32-unknown-unknown"
[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"wasm_js\""]

View File

@@ -28,6 +28,9 @@ rustpython-parser = { workspace = true }
serde = { workspace = true }
wasm-bindgen = { workspace = true }
# remove once getrandom 0.2 is no longer otherwise in the dependency tree
getrandom = { version = "0.2", features = ["js"] }
console_error_panic_hook = "0.1"
js-sys = "0.3"
serde-wasm-bindgen = "0.3.1"
@@ -47,4 +50,4 @@ web-sys = { version = "0.3", features = [
wasm-opt = false#["-O1"]
[lints]
workspace = true
workspace = true

View File

@@ -0,0 +1,5 @@
[build]
target = "wasm32-unknown-unknown"
[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"custom\""]

View File

@@ -8,6 +8,7 @@ crate-type = ["cdylib"]
[dependencies]
getrandom = { version = "0.2.12", features = ["custom"] }
getrandom_03 = { package = "getrandom", version = "0.3" }
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler"] }
[workspace]

View File

@@ -14,3 +14,11 @@ fn getrandom_always_fail(_buf: &mut [u8]) -> Result<(), getrandom::Error> {
}
getrandom::register_custom_getrandom!(getrandom_always_fail);
#[unsafe(no_mangle)]
unsafe extern "Rust" fn __getrandom_v03_custom(
_dest: *mut u8,
_len: usize,
) -> Result<(), getrandom_03::Error> {
Err(getrandom_03::Error::UNSUPPORTED)
}