Skip to content

Align POSIX control argument handling with Python 3.15 - #9664

Draft
youknowdot wants to merge 2 commits into
RustPython:mainfrom
youknowdot:fix-posix-control-conversion-order-315
Draft

youknowdot wants to merge 2 commits into
RustPython:mainfrom
youknowdot:fix-posix-control-conversion-order-315

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Align the related fcntl/termios control argument paths with CPython 3.15 while reusing typed/derived binding and existing buffer/descriptor helpers.

  • Prefer the integer protocol over buffer fallback in fcntl/ioctl and preserve conversion/exporter exceptions. Share unsigned-mask conversion and the 3.15 out-of-range DeprecationWarning behavior.
  • Convert ioctl request and mutation flag before inspecting its argument, retain raw argument roots, release immutable exports before the syscall, and use the existing guarded scratch buffer for writable input without holding its lock across a detached syscall.
  • Validate lockf arguments in CPython order and return None from flock/lockf.
  • Convert termios descriptors before later arguments, read attribute-list fields after prior conversion callbacks, use native signed narrowing, and validate control characters before libc speed checks.
  • Preserve sequential winsize conversion, I/O-before-range-check ordering, and existing pixel dimensions.

Only four production Rust files changed; no tests or snippets edited. Existing primitive integer conversion remains in use, so this does not introduce another per-function FuncArgs parser or duplicate shared argument machinery.

Reference

Compared against CPython v3.15.0 Modules/fcntlmodule.c, Modules/termios.c, their generated Clinic bindings, and Python/getargs.c.

Validation

Validated against base 0bdba72ff9a3ce7187798bb77ee6b5384481259c. Before publication, main advanced to 0b081b0283987c7b2d79327dd481f403d515580b with only unrelated Windows winreg changes (#9589). The four-file patch is identical against that newer main; the newer main was not locally rebuilt.

  • Focused VM, host_env, and stdlib threading cargo check --offline: passed.
  • Matching strict cargo clippy --offline -- -D warnings: passed.
  • Independent source review, formatting, git diff --check, and normal repository pre-commit hooks: passed.
  • Bounded CPython 3.15 reference probes used owned temporary files and PTYs to check conversion/callback order, warning boundaries, None returns, and native narrowing. No real terminal settings or undersized ioctl buffers were used.
  • Native RustPython execution, full workspace/C-API tests, and cross-platform builds were not run under the current task restrictions. Hosted CI remains required.

Generic C-int/C-long overflow diagnostic wording is unchanged. Platform-specific native layouts were reviewed in source but not exercised outside Linux.

AI assistance

OpenAI Codex assisted with source comparison, implementation, review, and validation. The model version is not exposed by this environment.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codspeed

codspeed Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 62 untouched benchmarks
⏩ 4 skipped benchmarks1


Comparing youknowdot:fix-posix-control-conversion-order-315 (e0e3258) with main (0b081b0)

Open in CodSpeed

Footnotes

  1. 4 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

struct FcntlArg {
#[pyarg(positional, default = 0)]
arg: Either<ArgStrOrBytesLike, ArgIndex>,
arg: PyObjectRef,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

check this change is necessary after #9563

Preserve fcntl and ioctl protocol precedence, unsigned warnings, buffer lifetimes and guards. Align lockf and termios conversion order, native narrowing, and return values using existing argument binding and host helpers.

Assisted-by: OpenAI Codex:model version not exposed
Widen BSD-family c_short lock constants to the shared c_int result while retaining checked flock-field conversion.

Assisted-by: OpenAI Codex:model version not exposed
@youknowdot
youknowdot force-pushed the fix-posix-control-conversion-order-315 branch from 3efe056 to 4712df2 Compare November 7, 2026 15:46
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.

2 participants