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

Commit fa2acd7

Browse filesBrowse files
coolreader18youknowone
authored andcommitted
Update rand to 0.9
1 parent a71c16f commit fa2acd7
Copy full SHA for fa2acd7

File tree

15 files changed

+50
-49
lines changed
Filter options

15 files changed

+50
-49
lines changed

‎.github/workflows/ci.yaml

Copy file name to clipboardExpand all lines: .github/workflows/ci.yaml
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ jobs:
379379
with: { wabt-version: "1.0.30" }
380380
- name: check wasm32-unknown without js
381381
run: |
382-
cargo build --release --manifest-path wasm/wasm-unknown-test/Cargo.toml --target wasm32-unknown-unknown --verbose
382+
cd wasm/wasm-unknown-test
383+
cargo build --release --verbose
383384
if wasm-objdump -xj Import target/wasm32-unknown-unknown/release/wasm_unknown_test.wasm; then
384385
echo "ERROR: wasm32-unknown module expects imports from the host environment" >2
385386
fi

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+10-10Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ cfg-if = "1.0"
146146
chrono = "0.4.39"
147147
crossbeam-utils = "0.8.21"
148148
flame = "0.2.2"
149-
getrandom = "0.2.15"
149+
getrandom = "0.3"
150150
glob = "0.3"
151151
hex = "0.4.3"
152152
indexmap = { version = "2.2.6", features = ["std"] }
@@ -168,7 +168,7 @@ num_enum = { version = "0.7", default-features = false }
168168
once_cell = "1.20.3"
169169
parking_lot = "0.12.3"
170170
paste = "1.0.15"
171-
rand = "0.8.5"
171+
rand = "0.9"
172172
rustix = { version = "0.38", features = ["event"] }
173173
rustyline = "15.0.0"
174174
serde = { version = "1.0.133", default-features = false }

‎common/src/hash.rs

Copy file name to clipboardExpand all lines: common/src/hash.rs
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ impl BuildHasher for HashSecret {
3737
}
3838
}
3939

40-
impl rand::distributions::Distribution<HashSecret> for rand::distributions::Standard {
40+
impl rand::distr::Distribution<HashSecret> for rand::distr::StandardUniform {
4141
fn sample<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> HashSecret {
4242
HashSecret {
43-
k0: rng.gen(),
44-
k1: rng.gen(),
43+
k0: rng.random(),
44+
k1: rng.random(),
4545
}
4646
}
4747
}

‎stdlib/Cargo.toml

Copy file name to clipboardExpand all lines: stdlib/Cargo.toml
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ xml-rs = "0.8.14"
5454

5555
# random
5656
rand = { workspace = true }
57-
rand_core = "0.6.4"
58-
mt19937 = "2.0.1"
57+
mt19937 = "3.1"
5958

6059
# Crypto:
6160
digest = "0.10.3"
@@ -88,7 +87,7 @@ bzip2 = { version = "0.4", optional = true }
8887
# uuid
8988
[target.'cfg(not(any(target_os = "ios", target_os = "android", target_os = "windows", target_arch = "wasm32", target_os = "redox")))'.dependencies]
9089
mac_address = "1.1.3"
91-
uuid = { version = "1.1.2", features = ["v1", "fast-rng"] }
90+
uuid = { version = "1.1.2", features = ["v1"] }
9291

9392
# mmap
9493
[target.'cfg(all(unix, not(target_arch = "wasm32")))'.dependencies]

‎stdlib/src/random.rs

Copy file name to clipboardExpand all lines: stdlib/src/random.rs
+1-7Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod _random {
2323

2424
impl Default for PyRng {
2525
fn default() -> Self {
26-
PyRng::Std(Box::new(StdRng::from_entropy()))
26+
PyRng::Std(Box::new(StdRng::from_os_rng()))
2727
}
2828
}
2929

@@ -46,12 +46,6 @@ mod _random {
4646
Self::MT(m) => m.fill_bytes(dest),
4747
}
4848
}
49-
fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> {
50-
match self {
51-
Self::Std(s) => s.try_fill_bytes(dest),
52-
Self::MT(m) => m.try_fill_bytes(dest),
53-
}
54-
}
5549
}
5650

5751
#[pyattr]

‎stdlib/src/uuid.rs

Copy file name to clipboardExpand all lines: stdlib/src/uuid.rs
+3-17Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,19 @@ mod _uuid {
55
use crate::{builtins::PyNone, vm::VirtualMachine};
66
use mac_address::get_mac_address;
77
use once_cell::sync::OnceCell;
8-
use rand::Rng;
9-
use std::time::{Duration, SystemTime};
10-
use uuid::{
11-
v1::{Context, Timestamp},
12-
Uuid,
13-
};
8+
use uuid::{timestamp::Timestamp, Context, Uuid};
149

1510
fn get_node_id() -> [u8; 6] {
1611
match get_mac_address() {
1712
Ok(Some(_ma)) => get_mac_address().unwrap().unwrap().bytes(),
18-
_ => rand::thread_rng().gen::<[u8; 6]>(),
13+
_ => rand::random::<[u8; 6]>(),
1914
}
2015
}
2116

22-
pub fn now_unix_duration() -> Duration {
23-
use std::time::UNIX_EPOCH;
24-
25-
let now = SystemTime::now();
26-
now.duration_since(UNIX_EPOCH)
27-
.expect("SystemTime before UNIX EPOCH!")
28-
}
29-
3017
#[pyfunction]
3118
fn generate_time_safe() -> (Vec<u8>, PyNone) {
3219
static CONTEXT: Context = Context::new(0);
33-
let now = now_unix_duration();
34-
let ts = Timestamp::from_unix(&CONTEXT, now.as_secs(), now.subsec_nanos());
20+
let ts = Timestamp::now(&CONTEXT);
3521

3622
static NODE_ID: OnceCell<[u8; 6]> = OnceCell::new();
3723
let unique_node_id = NODE_ID.get_or_init(get_node_id);

‎vm/Cargo.toml

Copy file name to clipboardExpand all lines: vm/Cargo.toml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ast = ["rustpython-ast"]
2323
codegen = ["rustpython-codegen", "ast"]
2424
parser = ["rustpython-parser", "ast"]
2525
serde = ["dep:serde"]
26-
wasmbind = ["chrono/wasmbind", "getrandom/js", "wasm-bindgen"]
26+
wasmbind = ["chrono/wasmbind", "getrandom/wasm_js", "wasm-bindgen"]
2727

2828
[dependencies]
2929
rustpython-compiler = { workspace = true, optional = true }
@@ -145,7 +145,7 @@ features = [
145145

146146
[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
147147
wasm-bindgen = { workspace = true, optional = true }
148-
getrandom = { workspace = true, features = ["custom"] }
148+
getrandom = { workspace = true }
149149

150150
[build-dependencies]
151151
glob = { workspace = true }

‎vm/src/import.rs

Copy file name to clipboardExpand all lines: vm/src/import.rs
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
vm::{thread, VirtualMachine},
99
AsObject, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
1010
};
11-
use rand::Rng;
1211

1312
pub(crate) fn init_importlib_base(vm: &mut VirtualMachine) -> PyResult<PyObjectRef> {
1413
flame_guard!("init importlib");
@@ -50,7 +49,7 @@ pub(crate) fn init_importlib_package(vm: &VirtualMachine, importlib: PyObjectRef
5049
let mut magic = get_git_revision().into_bytes();
5150
magic.truncate(4);
5251
if magic.len() != 4 {
53-
magic = rand::thread_rng().gen::<[u8; 4]>().to_vec();
52+
magic = rand::random::<[u8; 4]>().to_vec();
5453
}
5554
let magic: PyObjectRef = vm.ctx.new_bytes(magic).into();
5655
importlib_external.set_attr("MAGIC_NUMBER", magic, vm)?;

‎vm/src/stdlib/os.rs

Copy file name to clipboardExpand all lines: vm/src/stdlib/os.rs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ pub(super) mod _os {
978978
return Err(vm.new_value_error("negative argument not allowed".to_owned()));
979979
}
980980
let mut buf = vec![0u8; size as usize];
981-
getrandom::getrandom(&mut buf).map_err(|e| match e.raw_os_error() {
981+
getrandom::fill(&mut buf).map_err(|e| match e.raw_os_error() {
982982
Some(errno) => io::Error::from_raw_os_error(errno).into_pyexception(vm),
983983
None => vm.new_os_error("Getting random failed".to_owned()),
984984
})?;

‎wasm/lib/.cargo/config.toml

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
target = "wasm32-unknown-unknown"
3+
4+
[target.wasm32-unknown-unknown]
5+
rustflags = ["--cfg=getrandom_backend=\"wasm_js\""]

‎wasm/lib/Cargo.toml

Copy file name to clipboardExpand all lines: wasm/lib/Cargo.toml
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ rustpython-parser = { workspace = true }
2828
serde = { workspace = true }
2929
wasm-bindgen = { workspace = true }
3030

31+
# remove once getrandom 0.2 is no longer otherwise in the dependency tree
32+
getrandom = { version = "0.2", features = ["js"] }
33+
3134
console_error_panic_hook = "0.1"
3235
js-sys = "0.3"
3336
serde-wasm-bindgen = "0.3.1"
@@ -47,4 +50,4 @@ web-sys = { version = "0.3", features = [
4750
wasm-opt = false#["-O1"]
4851

4952
[lints]
50-
workspace = true
53+
workspace = true
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
target = "wasm32-unknown-unknown"
3+
4+
[target.wasm32-unknown-unknown]
5+
rustflags = ["--cfg=getrandom_backend=\"custom\""]

‎wasm/wasm-unknown-test/Cargo.toml

Copy file name to clipboardExpand all lines: wasm/wasm-unknown-test/Cargo.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ crate-type = ["cdylib"]
88

99
[dependencies]
1010
getrandom = { version = "0.2.12", features = ["custom"] }
11+
getrandom_03 = { package = "getrandom", version = "0.3" }
1112
rustpython-vm = { path = "../../vm", default-features = false, features = ["compiler"] }
1213

1314
[workspace]

‎wasm/wasm-unknown-test/src/lib.rs

Copy file name to clipboardExpand all lines: wasm/wasm-unknown-test/src/lib.rs
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ fn getrandom_always_fail(_buf: &mut [u8]) -> Result<(), getrandom::Error> {
1414
}
1515

1616
getrandom::register_custom_getrandom!(getrandom_always_fail);
17+
18+
#[unsafe(no_mangle)]
19+
unsafe extern "Rust" fn __getrandom_v03_custom(
20+
_dest: *mut u8,
21+
_len: usize,
22+
) -> Result<(), getrandom_03::Error> {
23+
Err(getrandom_03::Error::UNSUPPORTED)
24+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.