◐ Shell
clean mode source ↗

Windows execv, spawnv, wait by youknowone · Pull Request #6350 · RustPython/RustPython

Walkthrough

Added Windows-specific feature flag to Cargo.toml for Windows-sys dependency. Extended nt.rs module with new process spawn/exec functions (spawnv, spawnve, execv, execve), constants for spawn modes and I/O flags, and a restructured mkdir API using MkdirArgs struct. Changed waitpid/wait return types to accommodate larger exit codes.

Changes

Cohort / File(s) Summary
Windows-sys feature flag
crates/vm/Cargo.toml
Added Win32_Security_Authorization feature to Windows-sys dependency under Windows target.
Process spawn/exec functions
crates/vm/src/stdlib/nt.rs
Added MSVC extern C bindings for wide-character process functions (_wexecv, _wexecve, _wspawnv, _wspawnve). Introduced public wrappers spawnv, spawnve, execv, execve with argument validation and environment string assembly.
Process mode and I/O constants
crates/vm/src/stdlib/nt.rs
Added constants: P_WAIT, P_NOWAIT, P_OVERLAY, P_NOWAITO, P_DETACH for spawn modes; O_SHORT_LIVED for I/O flags; EX_OK and TMP_MAX for compatibility.
waitpid/wait return type changes
crates/vm/src/stdlib/nt.rs
Changed waitpid and wait return types from (intptr_t, i32) to (intptr_t, u64) to accommodate larger exit codes.
mkdir API restructuring
crates/vm/src/stdlib/nt.rs
Introduced MkdirArgs struct with configurable mode (default 0o777) and directory ACL handling. Refactored mkdir function to accept MkdirArgs instead of individual parameters. Added SDDL-based security descriptor construction for mode 0o700.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • Argument and environment validation logic: Verify that non-empty path elements, non-empty first argv elements, and embedded null/equals-sign checks in environment keys are correctly enforced across all new spawn/exec functions.
  • Wide-character conversion: Confirm proper UTF-8 to UTF-16 conversions for paths and arguments, and null-termination handling for MSVC interop.
  • mkdir ACL handling: Review SDDL-based security descriptor construction for mode 0o700 and verify correct application to created directories.
  • Return type changes: Ensure u64 return type for exit codes does not cause issues with existing callers and correctly maps MSVC exit codes.

Possibly related PRs

Poem

🐰 Windows bindings now take flight,
With spawn and exec shining bright,
Wide chars dancing, paths aligned,
mkdir's ACLs by design—
Process launching, done just right! 🪟✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main additions: Windows support for execv, spawnv functions and wait return type changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.