Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 203756d

Browse files
committed
Fix sysconfigdata platform-specific alias name registration
- Register _sysconfigdata under both short name and platform-specific name - Refactor sysconfigdata_name() to be reusable across modules - Add platform-specific name to sys.builtin_module_names - Eliminate code duplication in sysconfigdata name formatting This fixes the CI failure where sysconfig module imports '_sysconfigdata_t_darwin_aarch64-apple-darwin' but RustPython only registered '_sysconfigdata'. PyGlobalState
1 parent 8b7c26a commit 203756d

File tree

14 files changed

+162
-131
lines changed

14 files changed

+162
-131
lines changed

crates/common/src/crt_fd.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ use alloc::fmt;
55
use core::cmp;
66
use std::{ffi, io};
77

8+
#[cfg(unix)]
9+
use std::os::fd::AsFd;
810
#[cfg(not(windows))]
9-
use std::os::fd::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
11+
use std::os::fd::{AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, OwnedFd, RawFd};
1012
#[cfg(windows)]
1113
use std::os::windows::io::BorrowedHandle;
1214

crates/vm/src/stdlib/nt.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
// spell-checker:disable
22

3-
use crate::{PyRef, VirtualMachine, builtins::PyModule};
4-
53
pub(crate) use module::module_def;
64
pub use module::raw_set_handle_inheritable;
75

86
#[pymodule(name = "nt", with(super::os::_os))]
97
pub(crate) mod module {
108
use crate::{
11-
PyResult, TryFromObject, VirtualMachine,
9+
Py, PyResult, TryFromObject, VirtualMachine,
1210
builtins::{PyBaseExceptionRef, PyDictRef, PyListRef, PyStrRef, PyTupleRef},
1311
common::{crt_fd, suppress_iph, windows::ToWideString},
1412
convert::ToPyException,

crates/vm/src/stdlib/os.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ pub(super) mod _os {
149149
use super::{DirFd, FollowSymlinks, SupportFunc};
150150
#[cfg(windows)]
151151
use crate::common::windows::ToWideString;
152+
#[cfg(any(unix, windows))]
153+
use crate::utils::ToCString;
152154
use crate::{
153155
AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject,
154156
builtins::{
@@ -168,7 +170,6 @@ pub(super) mod _os {
168170
protocol::PyIterReturn,
169171
recursion::ReprGuard,
170172
types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter},
171-
utils::ToCString,
172173
vm::VirtualMachine,
173174
};
174175
use core::time::Duration;

crates/vm/src/stdlib/posix_compat.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// spell-checker:disable
22

33
//! `posix` compatible module for `not(any(unix, windows))`
4-
use crate::{PyRef, VirtualMachine, builtins::PyModule};
54
65
pub(crate) use module::module_def;
76

crates/vm/src/stdlib/stat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pub(crate) use stat::module_def;
1+
pub(crate) use _stat::module_def;
22

33
#[pymodule]
4-
mod stat {
4+
mod _stat {
55
// Use libc::mode_t for Mode to match the system's definition
66
#[cfg(unix)]
77
type Mode = libc::mode_t;

crates/vm/src/stdlib/symtable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pub(crate) use symtable::module_def;
1+
pub(crate) use _symtable::module_def;
22

33
#[pymodule]
4-
mod symtable {
4+
mod _symtable {
55
use crate::{
66
PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine,
77
builtins::{PyDictRef, PyStrRef},

crates/vm/src/stdlib/sys.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ mod sys {
7878
#[pyattr(name = "abiflags")]
7979
const ABIFLAGS_ATTR: &str = "t"; // 't' for free-threaded (no GIL)
8080
// Internal constant used for sysconfigdata_name
81-
pub(crate) const ABIFLAGS: &str = "t";
81+
pub const ABIFLAGS: &str = "t";
8282
#[pyattr(name = "api_version")]
8383
const API_VERSION: u32 = 0x0; // what C api?
8484
#[pyattr(name = "copyright")]
@@ -94,7 +94,7 @@ mod sys {
9494
#[pyattr(name = "maxunicode")]
9595
const MAXUNICODE: u32 = core::char::MAX as u32;
9696
#[pyattr(name = "platform")]
97-
pub(crate) const PLATFORM: &str = {
97+
pub const PLATFORM: &str = {
9898
cfg_if::cfg_if! {
9999
if #[cfg(target_os = "linux")] {
100100
"linux"
@@ -166,9 +166,11 @@ mod sys {
166166

167167
#[pyattr]
168168
fn builtin_module_names(vm: &VirtualMachine) -> PyTupleRef {
169-
let mut module_names: Vec<&str> = vm.state.module_defs.keys().copied().collect();
170-
module_names.push("sys");
171-
module_names.push("builtins");
169+
let mut module_names: Vec<String> =
170+
vm.state.module_defs.keys().map(|&s| s.to_owned()).collect();
171+
module_names.push("sys".to_owned());
172+
module_names.push("builtins".to_owned());
173+
172174
module_names.sort();
173175
vm.ctx.new_tuple(
174176
module_names
@@ -1673,7 +1675,7 @@ pub fn get_stderr(vm: &VirtualMachine) -> PyResult {
16731675
.map_err(|_| vm.new_runtime_error("lost sys.stderr"))
16741676
}
16751677

1676-
pub(crate) fn sysconfigdata_name() -> String {
1678+
pub fn sysconfigdata_name() -> String {
16771679
format!(
16781680
"_sysconfigdata_{}_{}_{}",
16791681
sys::ABIFLAGS,

crates/vm/src/stdlib/sysconfig.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
pub(crate) use sysconfig::module_def;
1+
pub(crate) use _sysconfig::module_def;
22

3-
#[pymodule(name = "_sysconfig")]
4-
pub(crate) mod sysconfig {
3+
#[pymodule]
4+
pub(crate) mod _sysconfig {
55
use crate::{VirtualMachine, builtins::PyDictRef, convert::ToPyObject};
66

77
#[pyfunction]

crates/vm/src/stdlib/sysconfigdata.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ mod _sysconfigdata {
1616
let build_time_vars = build_time_vars(vm);
1717
module.set_attr("build_time_vars", build_time_vars, vm)?;
1818

19-
// Add CPython-compatible alias to sys.modules
20-
let sysconfigdata_name = sysconfigdata_name();
19+
// Ensure the module is registered under the platform-specific name
20+
// (import_builtin() already handles this, but double-check for safety)
2121
let sys_modules = vm.sys_module.get_attr("modules", vm)?;
22+
let sysconfigdata_name = sysconfigdata_name();
2223
sys_modules.set_item(sysconfigdata_name.as_str(), module.to_owned().into(), vm)?;
24+
2325
Ok(())
2426
}
2527

crates/vm/src/stdlib/winreg.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// spell-checker:disable
22
#![allow(non_snake_case)]
33

4-
use crate::{PyRef, VirtualMachine, builtins::PyModule};
5-
64
pub(crate) use winreg::module_def;
75

86
#[pymodule]

0 commit comments

Comments
 (0)