GeezerVison is showing github.com — Fix sysconfigdata platform-specific alias name registration · RustPython/RustPython@22ea6ad
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: crates/common/src/crt_fd.rs +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,8 +5,10 @@ use alloc::fmt; | 5 | 5 | use core::cmp; | 6 | 6 | use std::{ffi, io}; | 7 | 7 |
| | 8 | +#[cfg(unix)] | | 9 | +use std::os::fd::AsFd; | 8 | 10 | #[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}; | 10 | 12 | #[cfg(windows)] | 11 | 13 | use std::os::windows::io::BorrowedHandle; | 12 | 14 |
| |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/import.rs +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -103,7 +103,11 @@ pub fn import_builtin(vm: &VirtualMachine, module_name: &str) -> PyResult { | 103 | 103 | sys_modules.set_item(module_name, module.clone().into(), vm)?; | 104 | 104 |
| 105 | 105 | // Phase 2: Call exec slot (can safely import other modules now) | 106 | | - def.exec_module(vm, &module)?; | | 106 | + // If exec fails, remove the partially-initialized module from sys.modules | | 107 | + if let Err(e) = def.exec_module(vm, &module) { | | 108 | + let _ = sys_modules.del_item(module_name, vm); | | 109 | + return Err(e); | | 110 | + } | 107 | 111 |
| 108 | 112 | return Ok(module.into()); | 109 | 113 | } | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/errno.rs +2-4Lines changed: 2 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,10 +16,8 @@ mod errno_mod { | 16 | 16 | for (name, code) in super::ERROR_CODES { | 17 | 17 | let name = vm.ctx.intern_str(*name); | 18 | 18 | let code = vm.new_pyobj(*code); | 19 | | - errorcode | 20 | | - .set_item(&*code, name.to_owned().into(), vm) | 21 | | - .unwrap(); | 22 | | - module.set_attr(name, code, vm).unwrap(); | | 19 | + errorcode.set_item(&*code, name.to_owned().into(), vm)?; | | 20 | + module.set_attr(name, code, vm)?; | 23 | 21 | } | 24 | 22 | Ok(()) | 25 | 23 | } | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/mod.rs +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -93,9 +93,7 @@ pub fn builtin_module_defs(ctx: &Context) -> Vec<&'static PyModuleDef> { | 93 | 93 | #[cfg(windows)] | 94 | 94 | nt::module_def(ctx), | 95 | 95 | operator::module_def(ctx), | 96 | | - #[cfg(unix)] | 97 | | - posix::module_def(ctx), | 98 | | - #[cfg(target_os = "wasi")] | | 96 | + #[cfg(any(unix, target_os = "wasi"))] | 99 | 97 | posix::module_def(ctx), | 100 | 98 | #[cfg(all( | 101 | 99 | any(not(target_arch = "wasm32"), target_os = "wasi"), | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/nt.rs +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // spell-checker:disable | 2 | 2 |
| 3 | | -use crate::{PyRef, VirtualMachine, builtins::PyModule}; | 4 | | - | 5 | 3 | pub(crate) use module::module_def; | 6 | 4 | pub use module::raw_set_handle_inheritable; | 7 | 5 |
| 8 | 6 | #[pymodule(name = "nt", with(super::os::_os))] | 9 | 7 | pub(crate) mod module { | 10 | 8 | use crate::{ | 11 | | - PyResult, TryFromObject, VirtualMachine, | | 9 | + Py, PyResult, TryFromObject, VirtualMachine, | 12 | 10 | builtins::{PyBaseExceptionRef, PyDictRef, PyListRef, PyStrRef, PyTupleRef}, | 13 | 11 | common::{crt_fd, suppress_iph, windows::ToWideString}, | 14 | 12 | convert::ToPyException, | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/os.rs +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -149,6 +149,8 @@ pub(super) mod _os { | 149 | 149 | use super::{DirFd, FollowSymlinks, SupportFunc}; | 150 | 150 | #[cfg(windows)] | 151 | 151 | use crate::common::windows::ToWideString; | | 152 | + #[cfg(any(unix, windows))] | | 153 | + use crate::utils::ToCString; | 152 | 154 | use crate::{ | 153 | 155 | AsObject, Py, PyObjectRef, PyPayload, PyRef, PyResult, TryFromObject, | 154 | 156 | builtins::{ | @@ -168,7 +170,6 @@ pub(super) mod _os { | 168 | 170 | protocol::PyIterReturn, | 169 | 171 | recursion::ReprGuard, | 170 | 172 | types::{IterNext, Iterable, PyStructSequence, Representable, SelfIter}, | 171 | | - utils::ToCString, | 172 | 173 | vm::VirtualMachine, | 173 | 174 | }; | 174 | 175 | use core::time::Duration; | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/posix_compat.rs -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | // spell-checker:disable | 2 | 2 |
| 3 | 3 | //! `posix` compatible module for `not(any(unix, windows))` | 4 | | -use crate::{PyRef, VirtualMachine, builtins::PyModule}; | 5 | 4 |
| 6 | 5 | pub(crate) use module::module_def; | 7 | 6 |
| |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/stat.rs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -pub(crate) use stat::module_def; | | 1 | +pub(crate) use _stat::module_def; | 2 | 2 |
| 3 | 3 | #[pymodule] | 4 | | -mod stat { | | 4 | +mod _stat { | 5 | 5 | // Use libc::mode_t for Mode to match the system's definition | 6 | 6 | #[cfg(unix)] | 7 | 7 | type Mode = libc::mode_t; | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/symtable.rs +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -pub(crate) use symtable::module_def; | | 1 | +pub(crate) use _symtable::module_def; | 2 | 2 |
| 3 | 3 | #[pymodule] | 4 | | -mod symtable { | | 4 | +mod _symtable { | 5 | 5 | use crate::{ | 6 | 6 | PyObjectRef, PyPayload, PyRef, PyResult, VirtualMachine, | 7 | 7 | builtins::{PyDictRef, PyStrRef}, | |
Collapse file Copy file name to clipboardExpand all lines: crates/vm/src/stdlib/sys.rs +7-5Lines changed: 7 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,7 +78,7 @@ mod sys { | 78 | 78 | #[pyattr(name = "abiflags")] | 79 | 79 | const ABIFLAGS_ATTR: &str = "t"; // 't' for free-threaded (no GIL) | 80 | 80 | // Internal constant used for sysconfigdata_name | 81 | | - pub(crate) const ABIFLAGS: &str = "t"; | | 81 | + pub const ABIFLAGS: &str = "t"; | 82 | 82 | #[pyattr(name = "api_version")] | 83 | 83 | const API_VERSION: u32 = 0x0; // what C api? | 84 | 84 | #[pyattr(name = "copyright")] | @@ -94,7 +94,7 @@ mod sys { | 94 | 94 | #[pyattr(name = "maxunicode")] | 95 | 95 | const MAXUNICODE: u32 = core::char::MAX as u32; | 96 | 96 | #[pyattr(name = "platform")] | 97 | | - pub(crate) const PLATFORM: &str = { | | 97 | + pub const PLATFORM: &str = { | 98 | 98 | cfg_if::cfg_if! { | 99 | 99 | if #[cfg(target_os = "linux")] { | 100 | 100 | "linux" | @@ -166,9 +166,11 @@ mod sys { | 166 | 166 |
| 167 | 167 | #[pyattr] | 168 | 168 | 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 | + | 172 | 174 | module_names.sort(); | 173 | 175 | vm.ctx.new_tuple( | 174 | 176 | module_names | |
|