Skip to content

Fix closerange empty ranges before unsigned conversion - #9031

Draft
youknowdot wants to merge 4 commits into
RustPython:mainfrom
youknowdot:fix/closerange-empty-range
Draft

youknowdot wants to merge 4 commits into
RustPython:mainfrom
youknowdot:fix/closerange-empty-range

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix empty os.closerange() ranges before converting the exclusive upper bound to an inclusive unsigned bound. After clamping the lower bound, equal bounds must return without calling close_range(). Otherwise an empty range with a zero upper bound can convert -1 to UINT_MAX and close every descriptor; other equal bounds must also be no-ops.

Refresh the existing PR by merging main df0d1b74c04408365f66666a03054d673dbccee7 append-only. The current-main diff contains only the Rust fix and its existing subprocess regression; the previously shared PyO3 benchmark-import correction is already on main and no longer appears in this PR's diff. No new tests, skips, or Lib changes are introduced by this refresh.

Regression coverage and reference limitation

The existing stdlib_os.py snippet runs the closerange regression in a child process. All RustPython no-op cases remain active: (0, 0), (-1, 0), positive equal bounds, positive reversed bounds, and (-2, -1). The single-descriptor case verifies adjacent descriptors remain open.

The exact CPython 3.15.0 Linux reference artifact reproduced python/cpython#159182; upstream fix #159183 remains open at this refresh. The existing guard excludes only the three documented zero/negative-upper-bound cases on CPython 3.15.0 final, Linux, with HAVE_CLOSE_RANGE. Other reference cases and all RustPython cases remain active. This refresh does not alter that guard or any assertion.

Validation

  • The resulting closerange function and complete existing stdlib_os.py snippet are byte-identical to previously tested PR head 5bc1814470459db99366b67e855c71d58d2f414c.
  • Existing canonical Lib/test/test_os closerange tests do not cover the empty/equal-bound regression; no duplicate snippet coverage was added during this refresh.
  • Fresh cargo check and strict cargo clippy -- -D warnings for rustpython-host_env --lib passed against the current-main composition (locked, offline, Linux target, fresh target directory). Input closure verification passed before and after both checks.
  • The first offline check stopped before compilation because the shared cache lacked registry xml; a separate cache populated with normal locked Cargo fetch resolved it without changing dependencies or Cargo.lock.
  • Normal commit hooks passed for merge commit 335a575a7e202501f683e1d07e945ed7fa44542b: merge-conflict and rustfmt passed; Ruff, redundant-test-patches and Prettier selected no files. Only cspell was excluded with the maintainer-authorized one-commit exception because its dependency setup was blocked. This is not a cspell pass.
  • The earlier head's hosted CI succeeded. This is historical evidence, not a claim that the current-main composition has passed CI or fresh interpreter runtime tests.
  • No full interpreter build, closerange execution, full workspace/C-API suite or unrelated GC-stress test was run locally for this refresh. Hosted correctness CI completed successfully for exact merge commit 335a575a7e202501f683e1d07e945ed7fa44542b: all 24 jobs passed, including Linux/macOS/Windows snippets and CPython tests and Rust tests. The Lib Dependencies Check workflow does not apply because this PR changes no Lib/** files.

AI assistance: dot inspected, prepared and reviewed the current-main refresh under maintainer direction. The runtime does not expose its exact model version.

@coderabbitai

coderabbitai Bot commented Oct 10, 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

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

@youknowdot
youknowdot force-pushed the fix/closerange-empty-range branch 2 times, most recently from 7c27a9f to 0a3d05a Compare October 11, 2026 03:01
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_mmap.py (TODO: 19)

dependencies:

dependent tests: (2 tests)

  • mmap: test_os
    • multiprocessing.shared_memory: test_genericalias

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@youknowdot
youknowdot force-pushed the fix/closerange-empty-range branch from 0a3d05a to 7ad6487 Compare October 11, 2026 03:21
@youknowone
youknowone changed the base branch from main to stack/python-3.15-8950 October 11, 2026 03:26
@youknowdot
youknowdot force-pushed the fix/closerange-empty-range branch from 7ad6487 to e1a5bb2 Compare October 11, 2026 04:07
@youknowone
youknowone changed the base branch from stack/python-3.15-8950 to main October 11, 2026 04:08
@youknowdot
youknowdot force-pushed the fix/closerange-empty-range branch from e1a5bb2 to 462147d Compare October 11, 2026 04:14
Return for equal bounds after clamping the lower bound. Retain subprocess-isolated Python regressions for empty, reversed, negative, and one-descriptor ranges. CPython builds with HAVE_CLOSE_RANGE retain the reference defect; do not weaken the regression.

Assisted-by: OpenAI Codex:model version unavailable
Import PyCodeInput from the types module, the canonical location in PyO3 0.30. The old ffi re-export is deprecated and fails Clippy with warnings denied.

Assisted-by: OpenAI Codex:model version unavailable
Keep every RustPython closerange regression active. Exclude only the three documented negative or zero-upper-bound cases on CPython 3.15.0 final Linux builds with HAVE_CLOSE_RANGE, pending python/cpython#159183 for issue #159182. Positive empty, reversed and one-descriptor reference cases remain active; later versions run all cases.

Assisted-by: OpenAI Codex:model version unavailable
@youknowdot
youknowdot force-pushed the fix/closerange-empty-range branch from 462147d to 5bc1814 Compare October 16, 2026 04:13
Merge current main without rewriting the existing branch. Preserve the exact
closerange implementation and existing subprocess regression, while removing
the already-landed PyO3 benchmark import correction from the PR diff.

AI assistance: dot prepared and reviewed this refresh under maintainer direction.
The runtime does not expose its exact model version.

Assisted-by: dot: model version not exposed
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