Skip to content

gh-159182: Preserve empty ranges in os.closerange - #159183

Open
youknowdot wants to merge 1 commit into
python:mainfrom
youknowdot:gh-159182-closerange-empty
Open

youknowdot wants to merge 1 commit into
python:mainfrom
youknowdot:gh-159182-closerange-empty

Conversation

@youknowdot

@youknowdot youknowdot commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #159182.

Check that the exclusive upper bound is positive and greater than the lower bound before subtracting one and calling _Py_closerange(). This keeps empty, inverted, and negative-only ranges as no-ops, avoids fd_high - 1 overflow for INT_MIN, and preserves the helper's handling of negative lower bounds for nonempty ranges.

The regression runs each boundary case in a subprocess and checks an independently opened descriptor. It uses exit status rather than the child's standard streams, which the bug can close. Includes a NEWS entry.

Validation on Linux x86-64, with a debug build based on current main (e878e1e9688ebaafbfae700a872fa30a9f86a4c4):

  • The new regression fails in seven of its nine subcases before the fix and passes after it.
  • ./python -m unittest -v test.test_os.test_os.FileTests: 23 tests, 3 platform-specific skips, otherwise passing.
  • An incremental variant with HAVE_CLOSE_RANGE undefined, recompiling both affected translation units and relinking, also passes these tests.
  • Additional isolated-child checks cover a positive nonempty range and a negative lower bound with a positive upper bound, including preservation of the exclusive upper endpoint.

AI assistance was used to investigate, implement, and test this change.

@python-cla-bot

python-cla-bot Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@StanFromIreland

Copy link
Copy Markdown
Member

We cnanot review unless the CI is signed.

@picnixz

picnixz commented Oct 11, 2026

Copy link
Copy Markdown
Member

@youknowone is it one of your accounts?

@youknowdot
youknowdot force-pushed the gh-159182-closerange-empty branch from b58cca4 to 2b9c948 Compare October 12, 2026 00:26
@youknowone

Copy link
Copy Markdown
Contributor

@picnixz hi, yes it is. this is mine. should i check policy about this?

@youknowdot
youknowdot marked this pull request as ready for review October 12, 2026 00:29
@picnixz

picnixz commented Oct 12, 2026

Copy link
Copy Markdown
Member

yes every commits must be associated with an account that signed the CLA

@msullivan msullivan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks right to me.

youknowdot added a commit to youknowdot/RustPython that referenced this pull request Oct 16, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

os.closerange(0, 0) closes an independently opened file descriptor

5 participants