Skip to content

Mask Windows single-wait timeouts - #9574

Merged
youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/windows-wait-timeout-mask-20261103
Nov 3, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
youknowdot:fix/windows-wait-timeout-mask-20261103

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

_winapi.WaitForSingleObject currently maps every negative timeout to INFINITE. CPython 3.15 parses the argument as a Windows unsigned-long bitfield: for example, -2 becomes 0xfffffffe rather than 0xffffffff, so the current behavior can wait indefinitely instead of using the requested timeout.

  • Accept indexable integers of arbitrary size and use their low 32 bits.
  • Match CPython's integer value out of range DeprecationWarning outside [-231, 232-1], propagating it when warnings are errors before starting the wait.
  • Preserve handle-first conversion and reject non-indexable values without invoking the wait.

This follows the CPython 3.15 Clinic wrapper, k argument conversion, and PyLong_AsNativeBytes. For an unusually long type name where a multibyte character crosses CPython's 50-byte diagnostic cutoff, RustPython preserves a valid UTF-8 boundary and may differ in the diagnostic. This change overlaps #9572; integration must preserve that PR's parameter names as well as this conversion.

Validation

  • Independent source review checked the integer range boundaries, low-bit masking, error and warning order, and warning-as-error path against CPython's code.
  • rustfmt --edition 2024 --check, git diff --check, and the normal commit hook passed.
  • Windows runtime, RustPython workspace/C API, and target tests were not run locally: the coordinated native execution guard and lock are absent and the offline dependency cache is incomplete. Hosted CI is pending. In particular, no live wait behavior or warning filter result is claimed as tested.

AI assistance

Implementation and source review were assisted by dot. The runtime does not expose its exact model version.

Summary by CodeRabbit

  • Bug Fixes
    • Windows wait timeouts now accept integer-like values. Values that cannot be interpreted as integers raise a TypeError, while errors raised during integer conversion are preserved.
    • Timeouts outside the supported range trigger a deprecation warning and are converted using unsigned 32-bit wrapping. Negative values no longer automatically mean an infinite timeout.

Use CPython 3.15 unsigned-long bitfield conversion, including its out-of-range deprecation warning, instead of treating every negative timeout as infinite.

Assisted-by: dot:frontier-intelligence
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

WaitForSingleObject now accepts a Python object for its timeout. It converts the value through the index protocol, warns for values outside the inclusive i32::MIN..=u32::MAX range, and applies unsigned 32-bit masking.

Changes: Windows API timeout conversion

Layer / File(s) Summary
Timeout conversion and validation
crates/vm/src/stdlib/_winapi.rs
WaitForSingleObject now raises TypeError for values that do not support index conversion and propagates conversion errors. It warns when the value is outside the specified range, then applies unsigned 32-bit masking. Negative values no longer map to infinite timeout, and values above u32::MAX are no longer rejected with OverflowError.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: youknowone

Merge Risk: Minimal · up to 9160d

No actionable merge-blocking issue is established for the timeout conversion change. Merge readiness remains subject to normal Windows CI checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Mask Windows single-wait timeouts" matches the main change. The PR changes _winapi.WaitForSingleObject so its timeout uses unsigned 32-bit masking, replacing the old behavior that mapped …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Mask Windows single-wait timeouts" matches the main change. The PR changes _winapi.WaitForSingleObject so its timeout uses unsigned 32-bit masking, replacing the old behavior that mapped negative values to infinite and raised OverflowError above u32::MAX. The title is short and specific. It does not name the deprecation warning, but it does not need to cover every detail.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • 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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 18fc82b and 9160d2f.

Files selected for processing: 1
  • crates/vm/src/stdlib/_winapi.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

@youknowone
youknowone marked this pull request as ready for review November 3, 2026 17:33
@youknowone
youknowone enabled auto-merge (squash) November 3, 2026 17:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T17:36:47.543289Z 9160d2f Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@youknowone
youknowone merged commit 7e1c3e9 into RustPython:main Nov 3, 2026
28 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.

2 participants