Skip to content

Fix stat module compilation for Redox OS #5857

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

Merged
merged 1 commit into from
Jun 28, 2025

Conversation

willnode
Copy link
Contributor

@willnode willnode commented Jun 28, 2025

Fixes #5856

The replacement constants is exist for redox and should be working: https://github.com/rust-lang/libc/blob/main/src/unix/redox/mod.rs

Summary by CodeRabbit

  • Bug Fixes
    • Corrected permissions constants to ensure accurate values are used on Redox OS. This improves compatibility and reliability for users on that platform.

Copy link

coderabbitai bot commented Jun 28, 2025

Walkthrough

The conditional compilation logic for the S_IWRITE and S_IEXEC constants in stat.rs was updated to explicitly exclude the Redox operating system from the Unix-specific branch. This ensures that Redox uses fallback octal values for these constants instead of relying on potentially unavailable libc values.

Changes

File(s) Change Summary
vm/src/stdlib/stat.rs Updated conditional compilation for S_IWRITE and S_IEXEC to exclude Redox from Unix branch.

Sequence Diagram(s)

sequenceDiagram
    participant RustPython
    participant OS

    RustPython->>OS: Detect target_os
    alt Unix and not Android and not Redox
        RustPython->>stat.rs: Use libc S_IWRITE/S_IEXEC
    else Android or not Unix or Redox
        RustPython->>stat.rs: Use fallback octal values (0o0200, 0o0100)
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Avoid use of obsolete S_IWRITE and S_IEXEC on Redox OS (#5856)
Ensure Redox uses fallback values for S_IWRITE and S_IEXEC (#5856)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes were found.

Poem

In the warren where the code does grow,
A Redox rabbit hopped to and fro.
"No more old constants!" it did decree,
Now octal values set us free.
With every hop, a bug erased—
RustPython’s stat is now well-placed!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2bd5212 and 02eb1bd.

📒 Files selected for processing (1)
  • vm/src/stdlib/stat.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.770Z
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
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.770Z
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.
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-26T12:52:11.109Z
Learning: Minimize modifications to CPython standard library files in the Lib/ directory; bug fixes should be made through Rust code modifications whenever possible.
vm/src/stdlib/stat.rs (3)
Learnt from: moreal
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.770Z
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
PR: RustPython/RustPython#5847
File: vm/src/stdlib/stat.rs:547-567
Timestamp: 2025-06-27T14:47:28.770Z
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.
Learnt from: CR
PR: RustPython/RustPython#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-06-26T12:52:11.109Z
Learning: Minimize modifications to CPython standard library files in the Lib/ directory; bug fixes should be made through Rust code modifications whenever possible.
🔇 Additional comments (2)
vm/src/stdlib/stat.rs (2)

135-140: Redox correctly excluded for S_IWRITE – change is sound

libc on Redox does not expose S_IWRITE, so falling back to the octal literal is the right fix and mirrors what we already do for Android. No functional or stylistic issues spotted.


149-154: Same-pattern fix for S_IEXEC looks good

Consistent with the previous hunk: Redox now uses the fallback value because libc lacks S_IEXEC. Implementation matches CPython behaviour for platforms without the constant.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@rw-vanc
Copy link

rw-vanc commented Jun 28, 2025

We probably need to fix S_IREAD as well.

I'm not entirely sure why S_IWRITE and S_IEXEC would be needed, but I think you should avoid them if you can.

And why are S_IRUSR, S_IWUSR and S_IXUSR all defined numerically (no libc::) but S_IREAD, S_IWRITE and S_IEXEC are defined using libc:: which will break on many Unixes. Why not define them in terms of S_IRUSR, S_IWUSR, and S_IXUSR?

@willnode
Copy link
Contributor Author

willnode commented Jun 28, 2025

@rw-vanc

I'm not quite understand about pub const S_IWRITE and S_IEXEC is used in the codebase so I'm just following along. The definition for S_IRUSR, S_IWUSR, and S_IXUSR is already exist in above of my changes and AFAIK redox is part of unix so no need changes in that part.

The python constants is already using Unix V7 synonym though.

@rw-vanc
Copy link

rw-vanc commented Jun 28, 2025

Yes, I reviewed the original code a little more, and I think a better fix would be to just define S_IREAD, S_IWRITE and S_IEXEC either in terms of S_IRUSR, S_IWUSR and S_IXUSR, or define them numerically always, as was done for the S_I{R,W,X}USR constants.

@youknowone
Copy link
Member

Thank you! We currently disabled redox CI due to broken github action

https://github.com/RustPython/RustPython/blob/main/.github/workflows/ci.yaml#L226-L232

Could someone help to fix it? Then this kind of breakage will be prevented

@willnode
Copy link
Contributor Author

I wish I can but currently redoxer itself is broken against recent kernel and the current CI always uses the new kernel. We'll figure out a way to fix it. Thanks for mentioning the CI 👍

@youknowone youknowone merged commit e41d7f5 into RustPython:main Jun 28, 2025
12 checks passed
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.

S_IWRITE and S_IEXEC are obsolete and break RustPython on Redox
4 participants