-
Notifications
You must be signed in to change notification settings - Fork 1.4k
nt.skiproot, winapi.LCMapStringEx #6399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis pull request adds Windows-specific functionality to the Rust VM: a CPython-like path splitting utility that decomposes Windows paths into drive, root, and tail components while preserving input type (str or bytes), and Windows API bindings for string locale mapping and named pipe creation with UTF-16 encoding/decoding support. Changes
Estimated code review effort🎯 3 (Moderate) | ���️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
crates/vm/src/stdlib/winapi.rs (1)
646-671: Consider using WTF-8 encoding for consistency.The
LCMapStringExfunction (line 570-574) usesas_wtf8().encode_wide()for proper surrogate handling, whileCreateNamedPipeusesas_str().to_wide_with_nul(). For consistency and to properly handle strings containing surrogates, consider using the same pattern:- let name_wide = args.name.as_str().to_wide_with_nul(); + let name_wide: Vec<u16> = args.name + .as_wtf8() + .encode_wide() + .chain(std::iter::once(0)) + .collect();While pipe names are typically ASCII paths like
\\.\pipe\name, using the WTF-8 aware encoding maintains consistency across the module.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (3)
Lib/test/test_fnmatch.pyis excluded by!Lib/**Lib/test/test_ntpath.pyis excluded by!Lib/**Lib/test/test_posixpath.pyis excluded by!Lib/**
📒 Files selected for processing (2)
crates/vm/src/stdlib/nt.rs(1 hunks)crates/vm/src/stdlib/winapi.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 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/vm/src/stdlib/nt.rscrates/vm/src/stdlib/winapi.rs
🧬 Code graph analysis (1)
crates/vm/src/stdlib/winapi.rs (1)
crates/wtf8/src/lib.rs (1)
from_wide(336-352)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (5)
crates/vm/src/stdlib/nt.rs (2)
573-643: LGTM! Well-implemented Windows path root detection.The
skiprootfunction correctly implements CPython's_Py_skiprootlogic, properly handling UNC paths, device paths (\\?\UNC\), drive letters, and relative paths. The safegetclosure pattern avoids bounds checking issues.
645-716: Well-structured implementation with proper type preservation.The function correctly:
- Handles path-like objects via
__fspath__- Uses WTF-8 encoding for
PyStrto handle surrogates- Validates UTF-8 for bytes input with appropriate error messages
- Preserves original separators by using
wide(notnormalized) for reconstruction- Returns the correct output type (bytes or str) matching the input type
crates/vm/src/stdlib/winapi.rs (3)
543-546: LGTM!Correctly defines
LOCALE_NAME_INVARIANTas an empty string, matching the Windows API specification.
548-624: Well-implemented locale string mapping with proper WTF-8 handling.The implementation correctly:
- Validates unsupported flags (matching CPython behavior)
- Uses WTF-8 encoding via
as_wtf8().encode_wide()for proper surrogate handling- Implements the standard two-phase Windows API pattern for buffer sizing
- Checks for
i32::MAXoverflow on input length- Uses
Wtf8Buf::from_widefor output which correctly handles unpaired surrogates
626-644: LGTM!The struct correctly defines all parameters for
CreateNamedPipeW. The ignored_security_attributesis appropriately documented.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.