◐ Shell
clean mode source ↗

Attempt to automate posix consts by ShaharNaveh · Pull Request #6117 · RustPython/RustPython

coderabbitai[bot]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (5)
vm/src/stdlib/posix.rs (5)

50-53: Fix FreeBSD import: drop Linux-only MFD_HUGE_MASK

MFD_HUGE_MASK isn’t defined on FreeBSD and will break that build. Keep only the SF_* flags here.

-#[cfg(target_os = "freebsd")]
-#[pyattr]
-use libc::{MFD_HUGE_MASK, SF_MNOWAIT, SF_NOCACHE, SF_NODISKIO, SF_SYNC};
+#[cfg(target_os = "freebsd")]
+#[pyattr]
+use libc::{SF_MNOWAIT, SF_NOCACHE, SF_NODISKIO, SF_SYNC};

87-93: Split memfd flags from POSIX_FADV_*; avoid FreeBSD/Android build breaks

MFD_* are Linux/Android-only. POSIX_FADV_* are also available on FreeBSD. Split the groups.

-#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
-#[pyattr]
-use libc::{
-    MFD_ALLOW_SEALING, MFD_CLOEXEC, MFD_HUGETLB, POSIX_FADV_DONTNEED, POSIX_FADV_NOREUSE,
-    POSIX_FADV_NORMAL, POSIX_FADV_RANDOM, POSIX_FADV_SEQUENTIAL, POSIX_FADV_WILLNEED,
-};
+// memfd_* flags: Linux/Android only
+#[cfg(any(target_os = "android", target_os = "linux"))]
+#[pyattr]
+use libc::{MFD_ALLOW_SEALING, MFD_CLOEXEC, MFD_HUGETLB};
+
+// posix_fadvise advice values (Android/FreeBSD/Linux)
+#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
+#[pyattr]
+use libc::{
+    POSIX_FADV_DONTNEED, POSIX_FADV_NOREUSE, POSIX_FADV_NORMAL, POSIX_FADV_RANDOM,
+    POSIX_FADV_SEQUENTIAL, POSIX_FADV_WILLNEED,
+};

94-97: Restrict TFD_ (timerfd) to Linux/Android*

NetBSD doesn’t provide timerfd.

-#[cfg(any(target_os = "android", target_os = "linux", target_os = "netbsd"))]
+#[cfg(any(target_os = "android", target_os = "linux"))]
 #[pyattr]
 use libc::{TFD_CLOEXEC, TFD_NONBLOCK, TFD_TIMER_ABSTIME, TFD_TIMER_CANCEL_ON_SET};

111-118: O_PATH is Linux-specific (Android may also expose); remove FreeBSD/Redox

This will fail on FreeBSD/Redox.

-#[cfg(any(
-    target_os = "android",
-    target_os = "freebsd",
-    target_os = "linux",
-    target_os = "redox"
-))]
+#[cfg(any(target_os = "android", target_os = "linux"))]
 #[pyattr]
 use libc::O_PATH;

120-127: Restrict O_RSYNC to Linux

O_RSYNC isn’t generally exposed on BSDs; Android’s support is unclear.

-#[cfg(any(
-    target_os = "android",
-    target_os = "linux",
-    target_os = "netbsd",
-    target_os = "openbsd"
-))]
-#[pyattr]
-use libc::O_RSYNC;
+#[cfg(target_os = "linux")]
+#[pyattr]
+use libc::O_RSYNC;
🧹 Nitpick comments (3)
vm/src/stdlib/posix.rs (3)

75-82: Nit: simplify cfg to unix

any(target_os = "android", unix) is redundant; Android is already unix.

-#[cfg(any(target_os = "android", unix))]
+#[cfg(unix)]
 #[pyattr]
 use libc::{
     F_OK, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, O_NONBLOCK, PRIO_PGRP, PRIO_PROCESS, PRIO_USER,
     R_OK, RTLD_GLOBAL, RTLD_LAZY, RTLD_LOCAL, RTLD_NOW, W_OK, WCONTINUED, WNOHANG, WUNTRACED,
     X_OK,
 };

193-208: Verify CLD_ and F_LOCK family coverage; consider dropping redox*

Some CLD_* and F_LOCK/TLOCK/ULOCK may not exist on Redox; broad gating risks build breaks.

-#[cfg(any(
+#[cfg(any(
     target_os = "android",
     target_os = "dragonfly",
     target_os = "freebsd",
     target_os = "linux",
     target_os = "macos",
     target_os = "netbsd",
-    target_os = "openbsd",
-    target_os = "redox"
+    target_os = "openbsd"
 ))]

209-221: Verify O_ASYNC/WEXITED/WNOWAIT/WSTOPPED on Redox

These waitid/async constants may be missing on Redox; suggest excluding if CI fails.

-#[cfg(any(
+#[cfg(any(
     target_os = "android",
     target_os = "dragonfly",
     target_os = "freebsd",
     target_os = "linux",
     target_os = "macos",
     target_os = "netbsd",
-    target_os = "openbsd",
-    target_os = "redox"
+    target_os = "openbsd"
 ))]
📜 Review details

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e9594c3 and 29c40ae.

📒 Files selected for processing (2)
  • scripts/libc_posix.py (1 hunks)
  • vm/src/stdlib/posix.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/libc_posix.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your 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:

  • vm/src/stdlib/posix.rs
🧠 Learnings (1)
📚 Learning: 2025-06-27T14:47:28.810Z
Learnt from: moreal
PR: RustPython/RustPython#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:

  • vm/src/stdlib/posix.rs
⏰ 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). (11)
  • GitHub Check: Run tests under miri
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run rust tests (ubuntu-latest)
🔇 Additional comments (11)
vm/src/stdlib/posix.rs (11)

54-57: LGTM: PIDFD_NONBLOCK gating is correct (Linux-only).


58-64: LGTM: Darwin-only constants and aliasing to _COPYFILE_DATA look good.


83-86: LGTM: O_SYMLINK correctly gated to macOS/redox.


102-110: LGTM: GRND_ coverage looks reasonable across the listed Unixes.*


149-159: LGTM: RTLD_NOLOAD gating looks fine.


160-169: LGTM: O_DSYNC across listed Unixes is reasonable.


171-181: LGTM: SCHED_OTHER exposure across these targets is fine.


139-147: Remove macOS from O_DIRECT (not a Darwin open(2) flag)

macOS uses F_NOCACHE via fcntl; O_DIRECT isn’t available there.

-#[cfg(any(
-    target_os = "android",
-    target_os = "dragonfly",
-    target_os = "freebsd",
-    target_os = "linux",
-    target_os = "netbsd"
-))]
+#[cfg(any(
+    target_os = "android",
+    target_os = "dragonfly",
+    target_os = "freebsd",
+    target_os = "linux",
+    target_os = "netbsd"
+))]
 #[pyattr]
 use libc::O_DIRECT;

Likely an incorrect or invalid review comment.


182-192: Keep Redox in the cfg since O_EXLOCK and O_SHLOCK are defined in Redox’s libc.

Likely an incorrect or invalid review comment.


98-101: Retain NetBSD in cfg NetBSD’s Linux-compatible sys/xattr.h defines XATTR_CREATE and XATTR_REPLACE, so the original #[cfg(any(target_os = "linux", target_os = "macos", target_os = "netbsd"))] is correct.

Likely an incorrect or invalid review comment.


129-137: Keep the single import; all three flags are supported on macOS and Android
macOS’s <dlfcn.h> defines RTLD_NODELETE and its headers (and Python itself) expose SEEK_DATA/SEEK_HOLE (opensource.apple.com, docs.python.org). Android’s Bionic <dlfcn.h> defines RTLD_NODELETE and its <unistd.h> pulls in bits/seek_constants.h for SEEK_DATA/SEEK_HOLE (android.googlesource.com). The existing #[cfg(any(target_os = "android", "dragonfly", "freebsd", "linux", "macos"))] use libc::{RTLD_NODELETE, SEEK_DATA, SEEK_HOLE}; is correct.

Likely an incorrect or invalid review comment.

Comment on lines +65 to +74

#[cfg(any(target_os = "android", target_os = "linux"))]
#[pyattr]
use libc::{
CLONE_FILES, CLONE_FS, CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS,
CLONE_NEWPID, CLONE_NEWUSER, CLONE_NEWUTS, CLONE_SIGHAND, CLONE_SYSVSEM, CLONE_THREAD,
CLONE_VM, EFD_CLOEXEC, EFD_NONBLOCK, EFD_SEMAPHORE, O_NOATIME, O_TMPFILE, P_PIDFD,
SCHED_BATCH, SCHED_IDLE, SCHED_RESET_ON_FORK, SPLICE_F_MORE, SPLICE_F_MOVE,
SPLICE_F_NONBLOCK,
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Split Linux-only flags from Android-safe ones; likely Android build break

Several items here are Linux-only or not guaranteed in bionic (e.g., P_PIDFD, O_TMPFILE, O_NOATIME, CLONE_NEW*). Keep eventfd on Android; move the rest to Linux-only.

-#[cfg(any(target_os = "android", target_os = "linux"))]
-#[pyattr]
-use libc::{
-    CLONE_FILES, CLONE_FS, CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS,
-    CLONE_NEWPID, CLONE_NEWUSER, CLONE_NEWUTS, CLONE_SIGHAND, CLONE_SYSVSEM, CLONE_THREAD,
-    CLONE_VM, EFD_CLOEXEC, EFD_NONBLOCK, EFD_SEMAPHORE, O_NOATIME, O_TMPFILE, P_PIDFD,
-    SCHED_BATCH, SCHED_IDLE, SCHED_RESET_ON_FORK, SPLICE_F_MORE, SPLICE_F_MOVE,
-    SPLICE_F_NONBLOCK,
-};
+# // Android + Linux: eventfd
+#[cfg(any(target_os = "android", target_os = "linux"))]
+#[pyattr]
+use libc::{EFD_CLOEXEC, EFD_NONBLOCK, EFD_SEMAPHORE};
+
+# // Linux-only: clone namespaces, pidfd, tmpfile, noatime, splice, sched_*
+#[cfg(target_os = "linux")]
+#[pyattr]
+use libc::{
+    CLONE_FILES, CLONE_FS, CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID,
+    CLONE_NEWUSER, CLONE_NEWUTS, CLONE_SIGHAND, CLONE_SYSVSEM, CLONE_THREAD, CLONE_VM, O_NOATIME,
+    O_TMPFILE, P_PIDFD, SCHED_BATCH, SCHED_IDLE, SCHED_RESET_ON_FORK, SPLICE_F_MORE, SPLICE_F_MOVE,
+    SPLICE_F_NONBLOCK,
+};

To confirm bionic coverage, please verify:


🌐 Web query:

Which of these constants are exposed by Android bionic's headers: P_PIDFD, O_TMPFILE, O_NOATIME, CLONE_NEWCGROUP?

💡 Result:

O_TMPFILE — yes. [1]
O_NOATIME — yes. [1]
CLONE_NEWCGROUP — yes. [2]
P_PIDFD — not exposed in bionic's public headers (bionic exposes pidfd APIs in <sys/pidfd.h>, but P_PIDFD itself is not defined there). [3][4]

Sources:

  • asm-generic fcntl.h (O_TMPFILE, O_NOATIME). [1]
  • linux sched.h (CLONE_NEWCGROUP). [2]
  • bionic <sys/pidfd.h> (pidfd APIs). [3]
  • linux/uapi pidfd header / userland references (shows pidfd flags but P_PIDFD is not in bionic headers). [4]

Only exclude P_PIDFD on Android; keep O_TMPFILE, O_NOATIME, CLONE_NEWCGROUP under Android+Linux

O_TMPFILE, O_NOATIME and CLONE_NEWCGROUP are defined in bionic’s asm-generic fcntl.h and linux/sched.h and safe on Android (android.googlesource.com). P_PIDFD is not defined in bionic’s public headers (sys/pidfd.h provides APIs but no P_PIDFD) (android.googlesource.com); move only P_PIDFD into the #[cfg(target_os = "linux")] block.

🤖 Prompt for AI Agents
In vm/src/stdlib/posix.rs around lines 65 to 74, the import currently excludes
the entire block on non-linux targets but the review notes P_PIDFD is the only
symbol missing on Android; update the cfg so O_TMPFILE, O_NOATIME and
CLONE_NEWCGROUP (and the other listed constants) remain under
#[cfg(any(target_os = "android", target_os = "linux"))] while moving P_PIDFD
into a separate #[cfg(target_os = "linux")] import line; adjust the use/libc
import(s) accordingly so all safe symbols are available on Android but P_PIDFD
is only imported for Linux.