◐ Shell
reader mode source ↗
Skip to content

Update urllib and windows libraries from v3.14.2#6858

Merged
youknowone merged 6 commits into
RustPython:mainfrom
youknowone:win-lib
Jan 24, 2026
Merged

Update urllib and windows libraries from v3.14.2#6858
youknowone merged 6 commits into
RustPython:mainfrom
youknowone:win-lib

Conversation

@youknowone

@youknowone youknowone commented Jan 24, 2026

Copy link
Copy Markdown
Member

#6839

Summary by CodeRabbit

  • New Features

    • Added several msvcrt functions (ungetch, ungetwch, kbhit, locking, heapmin) and related locking mode constants.
    • Exposed many additional Windows file-operation constants and a CreateFile wrapper for improved file access.
    • Enhanced test tooling to support multiple test paths, better extension-module test resolution, and more robust error handling.
  • Chores

    • Ensure UTF-8 encoding when reading/writing files in library migration scripts.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

These changes extend the Windows API bindings for RustPython by adding msvcrt functions (ungetch, ungetwch, kbhit, locking, heapmin), exposing FileSystem constants, and implementing a CreateFile wrapper. Update scripts are enhanced with explicit UTF-8 encoding and improved extension module test resolution.

Changes

Cohort / File(s) Summary
msvcrt bindings
crates/vm/src/stdlib/msvcrt.rs
Added FFI declarations and Python bindings for _ungetch, _ungetwch, _kbhit, _locking, _heapmin; added locking constants LK_UNLCK, LK_LOCK, LK_NBLCK, LK_RLCK, LK_NBRLCK; includes argument validation and errno-based error mapping.
_winapi FileSystem & CreateFile
crates/vm/src/stdlib/winapi.rs
Exposed many Windows FileSystem constants (COPY_FILE_, FILE_ATTRIBUTE_, FILE_FLAG_, FILE_SHARE_, FILE_TYPE_, OPEN_, PIPE_ACCESS_*, SYNCHRONIZE, TRUNCATE_EXISTING, etc.) and added CreateFile wrapper calling CreateFileW with wide-string conversion and NULL handling; returns WinHandle or OS error.
update_lib: migrate I/O encoding
scripts/update_lib/migrate.py
Added explicit encoding="utf-8" to all Path.read_text/write_text calls to ensure deterministic file I/O.
update_lib: multi-path tests & shortcuts
scripts/update_lib/quick.py
Added multi-test-path support (normalize test_paths), improved _expand_shortcut to handle extension-module test fallback (test/test_<name>), per-path processing in main, and user-friendly error handling; updated git_commit signature to accept multiple test paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

skip:ci

Suggested reviewers

  • ShaharNaveh

Poem

🐰
I hopped through bytes and constants bright,
Pushed CreateFile into the light,
Ungetch and heap trimmed tidy too,
UTF‑8 paths—clean and true,
A rabbit's cheer for code anew! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions 'urllib and windows libraries' but the changeset only updates Windows-related msvcrt and winapi bindings, with a minor encoding fix in migration scripts; urllib is not present in the changes. Change the title to accurately reflect the actual changes: something like 'Add msvcrt and winapi Windows library bindings' or 'Extend Windows API bindings for msvcrt and winapi'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@github-actions

github-actions Bot commented Jan 24, 2026

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • ruff check --select I --fix
    Please pull the latest changes before pushing again:
git pull origin win-lib

@youknowone youknowone marked this pull request as ready for review January 24, 2026 03:54

@coderabbitai coderabbitai Bot 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.

Hide comment

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/msvcrt.rs`:
- Line 36: The FFI declaration fn _locking and the public wrapper locking() use
i64 for the nbytes parameter which mismatches the Windows CRT ABI (should be
32-bit long); change the third parameter type from i64 to i32 in the extern "C"
fn _locking declaration and in the pub fn locking(...) wrapper signature and any
internal uses/casts in that wrapper to pass an i32. Ensure you do not try to
reference a non-existent _locking64 export; if larger ranges are needed, use
Win32 LockFile/LockFileEx instead.
🧹 Nitpick comments (1)
crates/vm/src/stdlib/msvcrt.rs (1)

122-125: Consider returning bool for kbhit() to match CPython.

CPython's msvcrt.kbhit() returns a boolean (True/False), while this implementation returns the raw i32. The current implementation works but doesn't strictly match Python semantics.

♻️ Optional: Return bool for Python compatibility
 #[pyfunction]
-fn kbhit() -> i32 {
-    unsafe { _kbhit() }
+fn kbhit() -> bool {
+    unsafe { _kbhit() != 0 }
 }

@coderabbitai coderabbitai Bot 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.

Hide comment

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@crates/vm/src/stdlib/winapi.rs`:
- Around line 119-153: The CreateFile wrapper currently ignores the passed-in
_security_attributes and _template_file but still accepts non-None values;
update CreateFile to validate these parameters (the _security_attributes and
_template_file PyObjectRef args) and reject any non-None input by returning a
Python error via the VirtualMachine (e.g., Err(vm.new_type_error(...)) or
vm.new_value_error(...)) with a clear message like "security_attributes must be
None" / "template_file must be None"; perform these checks before calling
CreateFileW so callers are explicitly informed the function does not support
non-None security/template arguments.
♻️ Duplicate comments (1)
crates/vm/src/stdlib/msvcrt.rs (1)

34-38: ABI mismatch: _locking expects 32‑bit long, not i64.

Using i64 risks UB in FFI calls. This matches the earlier review finding; please adjust both the extern signature and wrapper parameter to i32.

🛠️ Proposed fix
-        fn _locking(fd: i32, mode: i32, nbytes: i64) -> i32;
+        fn _locking(fd: i32, mode: i32, nbytes: i32) -> i32;
@@
-    fn locking(fd: i32, mode: i32, nbytes: i64, vm: &VirtualMachine) -> PyResult<()> {
+    fn locking(fd: i32, mode: i32, nbytes: i32, vm: &VirtualMachine) -> PyResult<()> {
MSVC _locking function signature and nbytes parameter type (long vs long long)

Also applies to: 127-135

@youknowone youknowone changed the title Upgrade windows libraries Jan 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

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

[+] lib: cpython/Lib/ntpath.py
[+] test: cpython/Lib/test/test_ntpath.py

dependencies:

  • ntpath

dependent tests: (3 tests)

  • ntpath: test_httpservers test_ntpath test_pathlib

[+] lib: cpython/Lib/nturl2path.py
[+] test: cpython/Lib/test/test_nturl2path.py

dependencies:

  • nturl2path

dependent tests: (no tests depend on nturl2path)

[+] lib: cpython/Lib/genericpath.py
[+] test: cpython/Lib/test/test_genericpath.py

dependencies:

  • genericpath

dependent tests: (16 tests)

  • genericpath: test_genericpath
    • ntpath: test_httpservers test_ntpath test_pathlib
    • posixpath: test_pathlib test_posixpath test_zipfile
      • fnmatch: test_fnmatch test_os
      • http.server: test_logging test_robotparser test_urllib2_localnet
      • importlib.metadata: test_importlib test_zoneinfo
      • wsgiref.util: test_wsgiref
      • zipfile._path: test_zipfile

[+] test: cpython/Lib/test/test_msvcrt.py

dependencies:

dependent tests: (1 tests)

  • msvcrt: test_msvcrt

[+] test: cpython/Lib/test/test_robotparser.py

dependencies:

dependent tests: (no tests depend on robotparser)

[+] lib: cpython/Lib/urllib
[+] test: cpython/Lib/test/test_urllib.py
[+] test: cpython/Lib/test/test_urllib2.py
[+] test: cpython/Lib/test/test_urllib2_localnet.py
[+] test: cpython/Lib/test/test_urllib2net.py
[+] test: cpython/Lib/test/test_urllibnet.py
[+] test: cpython/Lib/test/test_urlparse.py
[+] test: cpython/Lib/test/test_urllib_response.py
[+] test: cpython/Lib/test/test_robotparser.py

dependencies:

  • urllib

dependent tests: (26 tests)

  • urllib: test_genericalias test_http_cookiejar test_httpservers test_logging test_pathlib test_robotparser test_site test_sqlite3 test_ssl test_ucn test_urllib test_urllib2 test_urllib2_localnet test_urllib2net test_urllib_response test_urllibnet test_urlparse
    • email.utils: test_email test_smtplib
      • smtplib: test_smtpnet
    • http.client: test_docxmlrpc test_hashlib test_unicodedata test_wsgiref test_xmlrpc
    • pydoc: test_enum

[+] test: cpython/Lib/test/test_urllib2.py

dependencies:

dependent tests: (no tests depend on urllib2)

[+] test: cpython/Lib/test/test_urllib2_localnet.py

dependencies:

dependent tests: (no tests depend on urllib2_localnet)

[+] test: cpython/Lib/test/test_urllib2net.py

dependencies:

dependent tests: (no tests depend on urllib2net)

[+] test: cpython/Lib/test/test_urllibnet.py

dependencies:

dependent tests: (no tests depend on urllibnet)

[+] test: cpython/Lib/test/test_urlparse.py

dependencies:

dependent tests: (no tests depend on urlparse)

[+] test: cpython/Lib/test/test_winapi.py

dependencies:

dependent tests: (no tests depend on winapi)

Legend:

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

Hide details View details @youknowone youknowone merged commit 4963cc6 into RustPython:main Jan 24, 2026
14 checks passed
@youknowone youknowone deleted the win-lib branch January 24, 2026 15:19
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.

1 participant