Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 8, 2025

Summary by CodeRabbit

  • Refactor
    • Reworked OS process-exit handling to use distinct, platform-specific implementations for Unix and Windows, improving cross-platform correctness and maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Refactors waitstatus_to_exitcode into platform-specific implementations: a Unix variant under #[cfg(unix)] using i32 and WIFEXITED/WEXITSTATUS/WIFSIGNALED, and a new Windows variant accepting u64 that extracts the exit code via bit-shifting and validates it as u32. (47 words)

Changes

Cohort / File(s) Change Summary
Platform-specific waitstatus_to_exitcode refactor
crates/vm/src/stdlib/os.rs
Split the previous cross-platform function into two platform-guarded implementations: #[cfg(unix)] function uses status: i32 with WIFEXITED/WIFEXITSTATUS/WIFSIGNALED logic returning PyResult<i32>; a Windows-only function uses status: u64, extracts the exit code via status >> 8, validates it fits in u32, and returns PyResult<u32>. Removed prior combined cfg_if Windows handling from the Unix-guarded path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Single-file, focused platform split with small type/signature changes.
  • Pay attention to:
    • Call sites expecting the old signature/type.
    • Correct cfg attributes and exported visibility.
    • Consistent error handling and return types between platforms.

Possibly related PRs

Poem

🐰
Hops through code on nimble feet,
Unix paths and Windows meet,
Bits shift, macros softly sing,
Each platform gets its proper wing,
A carrot cheer for builds complete 🥕

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.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title 'os.waitstatus_to_exitcode for windows' accurately describes the main change: adding Windows support to the os.waitstatus_to_exitcode function by implementing a Windows-specific variant.

📜 Recent review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5b2b41 and f22bac7.

📒 Files selected for processing (1)
  • crates/vm/src/stdlib/os.rs (1 hunks)

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.

@youknowone youknowone marked this pull request as ready for review December 8, 2025 17:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/os.rs (1)

1442-1450: LGTM! Windows implementation correctly extracts exit code.

The >> 8 shift and u32 validation match CPython's Windows behavior. The distinct signature (u64 input, u32 output) appropriately reflects Windows semantics where exit codes are always non-negative.

Nitpick: Minor inconsistency in error message capitalization—line 1439 uses "Invalid" while line 1449 uses "invalid". Consider aligning for consistency.

-        .map_err(|_| vm.new_value_error(format!("invalid exit code: {exitcode}")))
+        .map_err(|_| vm.new_value_error(format!("Invalid exit code: {exitcode}")))
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3d638a and c5b2b41.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_os.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/stdlib/os.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 running cargo fmt to 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/os.rs
🧠 Learnings (2)
📓 Common learnings
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration rather than providing fallback values for other platforms.
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
Repo: RustPython/RustPython PR: 5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.810Z
Learning: In RustPython's stat module implementation, platform-specific constants like SF_SUPPORTED and SF_SYNTHETIC should be conditionally declared only for the platforms where they're available (e.g., macOS), following CPython's approach of optional declaration using #ifdef checks rather than providing fallback values for other platforms.

Applied to files:

  • crates/vm/src/stdlib/os.rs
🔇 Additional comments (1)
crates/vm/src/stdlib/os.rs (1)

1424-1440: LGTM! Unix implementation correctly handles wait status.

The implementation properly uses libc macros (WIFEXITED/WEXITSTATUS/WIFSIGNALED/WTERMSIG) and correctly returns negative values for signal-terminated processes. The validation flow (i32 → u32 → c_int) ensures non-negative input while maintaining compatibility with libc macro expectations.

Based on learnings, this follows the recommended pattern of platform-specific conditional compilation.

@youknowone youknowone changed the title fix waitstatus_to_exitcode os.waitstatus_to_exitcode for windows Dec 8, 2025
@youknowone youknowone merged commit abc5c22 into RustPython:main Dec 8, 2025
12 of 13 checks passed
@youknowone youknowone deleted the waitstatus_to_exitcode branch December 8, 2025 17:46
@coderabbitai coderabbitai bot mentioned this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant