rustix/windows-sys for page size; drop maplit (#7876)

The `page_size` crate is a simple libc wrapper for Unix and uses
`winapi-rs` for Windows. `windows-sys` and `windows-rs` are the modern
alternatives for the unmaintained `winapi-rs`. Both crates are
maintained by Microsoft - they're official. Getting the page size is a
simple call for both Unix and Windows.

Besides Unix and Windows, I also added the page size for wasm32 which
the `page_size` crate did not support. `wasm32`'s page size is a
constant that is defined by the spec, so I hard coded it without adding
additional dependencies.

Finally, I dropped `maplit` which is seven years old and only used in
one place. Calling `collect()` with a single item iterator is idiomatic
as well as better in this case because Rust can optimize it. `maplit`
called `HashMap::insert` which over allocates to amortize future allocs.
This commit is contained in:
Joshua Megnauth authored and GitHub committed 2026-05-17 20:47:13 +09:00
1 parent 8367256315
commit 2c558fa749
9 files changed
+52 -25

No files matched your search

Generated
-8
View File
@@ -2141,12 +2141,6 @@ dependencies = [
"quote",
]
[[package]]
name = "maplit"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d"
[[package]]
name = "md-5"
version = "0.10.6"
@@ -3331,7 +3325,6 @@ name = "rustpython-derive-impl"
version = "0.5.0"
dependencies = [
"itertools 0.14.0",
"maplit",
"proc-macro2",
"quote",
"rustpython-compiler-core",
@@ -3541,7 +3534,6 @@ dependencies = [
"openssl",
"openssl-probe",
"openssl-sys",
"page_size",
"parking_lot",
"paste",
"pbkdf2",
+1 -3
View File
@@ -233,7 +233,6 @@ mac_address = "1.1.3"
malachite-bigint = "0.9.1"
malachite-q = "0.9.1"
malachite-base = "0.9.1"
maplit = "1.0.2"
md-5 = "0.10.1"
memchr = "2.8.0"
memmap2 = "0.9.10"
@@ -248,7 +247,6 @@ openssl = "0.10.79"
openssl-sys = "0.9.110"
openssl-probe = "0.2.1"
optional = "0.5"
page_size = "0.6"
parking_lot = "0.12.3"
paste = "1.0.15"
pbkdf2 = "0.12"
@@ -263,7 +261,7 @@ radium = "1.1.1"
rand = "0.9"
rand_core = { version = "0.9", features = ["os_rng"] }
result-like = "0.5.0"
rustix = { version = "1.1", features = ["event", "system"] }
rustix = { version = "1.1", features = ["event", "param", "system"] }
rustls = { version = "0.23.39", default-features = false }
rustls-native-certs = "0.8"
rustls-pemfile = "2.2"
-1
View File
@@ -16,7 +16,6 @@ rustpython-doc = { workspace = true }
itertools = { workspace = true }
syn = { workspace = true, features = ["full", "extra-traits"] }
maplit = { workspace = true }
proc-macro2 = { workspace = true }
quote = { workspace = true }
syn-ext = { workspace = true, features = ["full"] }
+5 -3
View File
@@ -83,12 +83,14 @@ impl CompilationSource {
CompilationSourceKind::Dir { base, rel_path } => {
self.compile_dir(base, &base.join(rel_path), "", mode, compiler)
}
_ => Ok(hashmap! {
module_name.to_string() => CompiledModule {
_ => Ok(core::iter::once((
module_name.to_string(),
CompiledModule {
code: self.compile_single(mode, module_name, compiler)?,
package: false,
},
}),
))
.collect()),
}
}
-3
View File
@@ -4,9 +4,6 @@
extern crate proc_macro;
#[macro_use]
extern crate maplit;
#[macro_use]
mod error;
#[macro_use]
+1 -3
View File
@@ -19,10 +19,8 @@ paste = { workspace = true }
[target.'cfg(unix)'.dependencies]
nix = { workspace = true }
uname = "0.1.1"
[target.'cfg(any(target_os = "linux", target_os = "android", target_os = "redox"))'.dependencies]
rustix = { workspace = true }
uname = "0.1.1"
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))'.dependencies]
num_cpus = "1.17.0"
+43
View File
@@ -25,6 +25,7 @@ use {
Storage::FileSystem::{
FILE_FLAG_BACKUP_SEMANTICS, INVALID_SET_FILE_POINTER, SetFilePointer, SetFileTime,
},
System::SystemInformation::{GetSystemInfo, SYSTEM_INFO},
},
};
@@ -132,6 +133,48 @@ pub fn cpu_count() -> usize {
1
}
#[cfg(unix)]
pub fn page_size() -> usize {
rustix::param::page_size()
}
#[cfg(target_arch = "wasm32")]
pub const fn page_size() -> usize {
// WebAssembly's page size is a constant defined by the spec.
1024 * 64
}
#[cfg(windows)]
pub fn page_size() -> usize {
let mut info = SYSTEM_INFO::default();
unsafe {
GetSystemInfo(&mut info);
}
info.dwPageSize as _
}
#[cfg(unix)]
pub fn alloc_granularity() -> usize {
// On Unix-likes, the page size is the smallest allocation unit rather than a separate concept
// of allocation granularity.
page_size()
}
#[cfg(target_arch = "wasm32")]
pub const fn alloc_granularity() -> usize {
// Like Unix, WebAssembly doesn't separate page size and alloc granularity.
page_size()
}
#[cfg(windows)]
pub fn alloc_granularity() -> usize {
let mut info = SYSTEM_INFO::default();
unsafe {
GetSystemInfo(&mut info);
}
info.dwAllocationGranularity as _
}
pub fn device_encoding(_fd: i32) -> Option<String> {
#[cfg(any(
target_os = "android",
-1
View File
@@ -102,7 +102,6 @@ uuid = { workspace = true, features = ["v1"] }
# mmap + socket dependencies
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
page_size = { workspace = true }
gethostname = { workspace = true }
socket2 = { workspace = true, features = ["all"] }
dns-lookup = { workspace = true }
+2 -3
View File
@@ -131,16 +131,15 @@ mod mmap {
#[pyattr]
const ACCESS_COPY: u32 = AccessMode::Copy as u32;
#[cfg(not(target_arch = "wasm32"))]
#[pyattr(name = "PAGESIZE", once)]
fn page_size(_vm: &VirtualMachine) -> usize {
page_size::get()
rustpython_host_env::os::page_size()
}
#[cfg(not(target_arch = "wasm32"))]
#[pyattr(name = "ALLOCATIONGRANULARITY", once)]
fn granularity(_vm: &VirtualMachine) -> usize {
page_size::get_granularity()
rustpython_host_env::os::alloc_granularity()
}
#[pyattr(name = "error", once)]