GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — nt is_dir,is_file,listmount,listvolume by youknowone · Pull Request #6373 · RustPython/RustPython Conversation
|
WalkthroughThese changes introduce Windows-specific functionality: a new maximum environment variable constant, two volume enumeration functions for the nt module ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ac19e43 to
2dab1f6
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Lib/test/test_os.py is excluded by !Lib/**crates/common/src/windows.rs (1 hunks)crates/vm/src/stdlib/nt.rs (1 hunks)crates/vm/src/stdlib/os.rs (5 hunks)📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/common/src/windows.rscrates/vm/src/stdlib/nt.rscrates/vm/src/stdlib/os.rsLearnt from: arihant2math
Repo: RustPython/RustPython PR: 5790
File: build.rs:2-2
Timestamp: 2025-06-28T16:31:03.991Z
Learning: In Cargo build scripts (build.rs), the environment variable CARGO_CFG_TARGET_OS is guaranteed to exist and is automatically set by Cargo during the build process, making unwrap() safe to use when accessing this variable.
Applied to files:
crates/vm/src/stdlib/os.rscrates/vm/src/stdlib/os.rs (1)
errno_err(39-41)
crates/vm/src/stdlib/nt.rs (2)
685-717: LGTM! Volume enumeration implementation looks correct.The handle lifecycle is properly managed:
FindVolumeCloseis called on anyFindNextVolumeWfailure, covering both normal termination (ERROR_NO_MORE_FILES) and error conditions. The buffer size ofMAX_PATH + 1is appropriate for volume GUIDs.Minor observation:
from_utf16_lossysilently replaces invalid sequences. This is acceptable for volume names which should always be valid UTF-16.
719-764: LGTM! Mount path enumeration handles dynamic buffer sizing correctly.The retry loop for
ERROR_MORE_DATAwith buffer resizing follows the standard Windows pattern. The null-separated string parsing with double-null termination detection (lines 757-758) is correct.crates/common/src/windows.rs (1)
6-8: LGTM!The constant value 32767 correctly matches the Windows CRT
_MAX_ENVdefinition, and the doc comment clearly identifies the source.crates/vm/src/stdlib/os.rs (3)
431-443: LGTM! Windows environment variable length validation.The helper function correctly validates against
_MAX_ENVand provides a clear error message.
529-546: LGTM! Windows fallback foris_dirhandles race conditions.The fallback to cached
file_typewhen the file is removed between directory enumeration and theis_dircall is a sensible approach for Windows. This matches CPython's behavior of using directory entry metadata when the file no longer exists.
548-565: LGTM! Consistent pattern withis_dir.The
is_filerefactoring mirrors theis_dirimplementation with the same Windows-specific fallback to cachedfile_typeonNotFound.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // For unsetenv, size is key + '=' (no value, just clearing) | ||
| #[cfg(windows)] | ||
| check_env_var_len(key.len() + 1, vm)?; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Potential off-by-one: missing null terminator in size calculation.
The comment states "size is key + '='" but Windows _MAX_ENV includes the null terminator. For unsetenv, Windows internally sets "KEY=\0", so the size should be key.len() + 2 (key + '=' + '\0'), not key.len() + 1.
// For unsetenv, size is key + '=' (no value, just clearing)
#[cfg(windows)]
- check_env_var_len(key.len() + 1, vm)?;
+ check_env_var_len(key.len() + 2, vm)?; // key + '=' + '\0'
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // For unsetenv, size is key + '=' (no value, just clearing) | |
| #[cfg(windows)] | |
| check_env_var_len(key.len() + 1, vm)?; | |
| // For unsetenv, size is key + '=' (no value, just clearing) | |
| #[cfg(windows)] | |
| check_env_var_len(key.len() + 2, vm)?; // key + '=' + '\0' |
In crates/vm/src/stdlib/os.rs around lines 483 to 485, the size computed for
unsetenv on Windows omits the null terminator; change the Windows branch to pass
key.len() + 2 (key + '=' + '\0') into check_env_var_len instead of key.len() + 1
so the length accounts for the terminating NUL when validating against _MAX_ENV.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.