Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Update rand to 0.9 #5527

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

Merged
merged 1 commit into from
Feb 18, 2025
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
3 changes: 2 additions & 1 deletion 3 .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,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
Expand Down
20 changes: 10 additions & 10 deletions 20 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 4 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions 6 common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions 5 stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down
8 changes: 1 addition & 7 deletions 8 stdlib/src/random.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
}

Expand All @@ -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]
Expand Down
20 changes: 3 additions & 17 deletions 20 stdlib/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions 4 vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -144,7 +144,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 }
Expand Down
3 changes: 1 addition & 2 deletions 3 vm/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion 2 vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
})?;
Expand Down
5 changes: 5 additions & 0 deletions 5 wasm/lib/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "wasm32-unknown-unknown"

[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"wasm_js\""]
5 changes: 4 additions & 1 deletion 5 wasm/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -47,4 +50,4 @@ web-sys = { version = "0.3", features = [
wasm-opt = false#["-O1"]

[lints]
workspace = true
workspace = true
5 changes: 5 additions & 0 deletions 5 wasm/wasm-unknown-test/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
target = "wasm32-unknown-unknown"

[target.wasm32-unknown-unknown]
rustflags = ["--cfg=getrandom_backend=\"custom\""]
1 change: 1 addition & 0 deletions 1 wasm/wasm-unknown-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
8 changes: 8 additions & 0 deletions 8 wasm/wasm-unknown-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.