GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — A few windows fix by youknowone · Pull Request #7458 · RustPython/RustPython

Conversation

@youknowone

@youknowone youknowone commented Mar 17, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes

    • Fixed Windows environment variable block serialization for empty environment mappings
    • Prevented direct instantiation of sys.getwindowsversion type on Windows
  • Changes

    • Updated exception type for memory map resize failures on Windows
    • Removed Windows socket error constant from errno exports

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions

github-actions Bot commented Mar 17, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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: 1)

dependencies:

dependent tests: (2 tests)

  • mmap: test_os
    • multiprocessing.shared_memory: test_genericalias

[x] lib: cpython/Lib/subprocess.py
[x] test: cpython/Lib/test/test_subprocess.py (TODO: 3)

dependencies:

  • subprocess

dependent tests: (81 tests)

  • subprocess: test_android test_asyncio test_atexit test_audit test_bz2 test_c_locale_coercion test_cmd_line test_cmd_line_script test_ctypes test_dtrace test_faulthandler test_file_eintr test_gc test_gzip test_inspect test_json test_launcher test_msvcrt test_ntpath test_os test_osx_env test_platform test_plistlib test_poll test_py_compile test_quopri test_regrtest test_repl test_runpy test_script_helper test_select test_shutil test_signal test_site test_sqlite3 test_subprocess test_support test_sys test_sysconfig test_tempfile test_threading test_traceback test_unittest test_urllib2 test_utf8_mode test_venv test_wait3 test_webbrowser test_zipfile
    • asyncio: test_asyncio test_contextlib_async test_logging test_sys_settrace test_unittest
    • ctypes.util: test_ctypes
    • ensurepip: test_ensurepip
    • http.server: test_httpservers test_robotparser test_urllib2_localnet test_xmlrpc
      • pydoc: test_enum test_pydoc
      • wsgiref.simple_server: test_wsgiref
      • xmlrpc.server: test_docxmlrpc
    • imaplib: test_imaplib
    • multiprocessing.util: test_compileall test_concurrent_futures
    • platform: test__locale test__osx_support test_baseexception test_builtin test_cmath test_fcntl test_math test_mimetypes test_posix test_socket test_ssl test_time test_winreg
    • uuid:
      • wave: test_wave

[x] test: cpython/Lib/test/test_sys.py (TODO: 7)
[ ] test: cpython/Lib/test/test_syslog.py (TODO: 2)
[ ] test: cpython/Lib/test/test_sys_setprofile.py
[ ] test: cpython/Lib/test/test_sys_settrace.py (TODO: 45)
[ ] test: cpython/Lib/test/test_audit.py
[ ] test: cpython/Lib/test/audit-tests.py

dependencies:

dependent tests: (225 tests)

  • sys: regrtestdata test___all__ test__colorize test__locale test__osx_support test_android test_annotationlib test_argparse test_array test_ast test_asyncio test_audit test_bdb test_bigaddrspace test_bigmem test_bisect test_buffer test_builtin test_bytes test_bz2 test_c_locale_coercion test_calendar test_call test_class test_cmath test_cmd test_cmd_line test_cmd_line_script test_code test_code_module test_codeccallbacks test_codecs test_collections test_compile test_compileall test_complex test_concurrent_futures test_context test_contextlib test_coroutines test_csv test_ctypes test_datetime test_dbm test_dbm_sqlite3 test_decimal test_descr test_dict test_difflib test_dis test_doctest test_doctest2 test_docxmlrpc test_dtrace test_dynamic test_dynamicclassattribute test_email test_ensurepip test_enum test_enumerate test_eof test_except_star test_exceptions test_faulthandler test_fcntl test_file test_file_eintr test_fileinput test_fileio test_float test_fork1 test_format test_fractions test_frame test_frozen test_functools test_future_stmt test_gc test_generators test_genericpath test_getopt test_glob test_grammar test_gzip test_hash test_hashlib test_http_cookiejar test_httpservers test_importlib test_inspect test_int test_io test_iter test_itertools test_json test_largefile test_launcher test_list test_listcomps test_locale test_logging test_long test_lzma test_mailbox test_marshal test_math test_memoryio test_memoryview test_metaclass test_mimetypes test_mmap test_monitoring test_msvcrt test_multiprocessing_forkserver test_multiprocessing_main_handling test_multiprocessing_spawn test_netrc test_ntpath test_numeric_tower test_operator test_optparse test_ordered_dict test_os test_osx_env test_pathlib test_patma test_peepholer test_pickle test_pkg test_pkgutil test_platform test_plistlib test_popen test_posix test_posixpath test_print test_property test_pty test_pwd test_py_compile test_pyclbr test_pydoc test_pyexpat test_quopri test_raise test_range test_re test_regrtest test_repl test_reprlib test_resource test_runpy test_sax test_scope test_script_helper test_select test_selectors test_shutil test_signal test_site test_slice test_smtplib test_socket test_sqlite3 test_ssl test_stable_abi_ctypes test_stat test_statistics test_str test_strftime test_string_literals test_strtod test_struct test_subprocess test_support test_sys test_sys_setprofile test_sys_settrace test_sysconfig test_syslog test_tarfile test_tempfile test_termios test_threadedtempfile test_threading test_threading_local test_threadsignals test_time test_timeit test_tomllib test_tools test_trace test_traceback test_tuple test_type_comments test_types test_typing test_unicode_file test_unicode_file_functions test_unicodedata test_unittest test_univnewlines test_urllib test_urllib2 test_urllib2net test_urlparse test_utf8_mode test_uuid test_venv test_wait3 test_wait4 test_wave test_weakref test_webbrowser test_winconsoleio test_winreg test_with test_wsgiref test_xml_etree test_xmlrpc test_zipapp test_zipfile test_zipfile64 test_zipimport test_zlib

Legend:

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request refines Windows-specific standard library implementations across four files: adjusts exception types in memory mapping operations, fixes environment block serialization for empty mappings, removes deprecated WinSock constants, and prevents direct instantiation of the Windows version struct.

Changes

Cohort / File(s) Summary
Memory Mapping Exception Handling
crates/stdlib/src/mmap.rs
Changed exception type from SystemError to OSError when attempting to resize a named memory mapping on Windows, keeping the error message unchanged.
Environment Block Serialization
crates/vm/src/stdlib/_winapi.rs
Added conditional logic to append an extra null terminator when environment block is empty, producing \0\0 for empty environments before the final trailing \0.
WinSock Constants Cleanup
crates/vm/src/stdlib/errno.rs
Removed WSAHOS constant definition and its export from Windows error codes; replaced ERROR_CODES entry with a commented TODO rather than a macro invocation.
Windows Version Constructor Guard
crates/vm/src/stdlib/sys.rs
Added custom constructor slot to PyWindowsVersion that raises TypeError to prevent direct instantiation of sys.getwindowsversion objects.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Implement Windows named mmap via CreateFileMappingW #7207: Implements named mmap support on Windows; the main PR refines exception handling for the resize operation introduced by this PR.
  • mmap for windows #6329: Addresses the same mmap resize error path on Windows that this PR modifies, switching from SystemError to OSError.

Poem

🐰 On Windows paths, we hop and refine,
Environment blocks and mmaps align,
WinSock dust swept, constructors locked tight,
Error types cleaned for clarity bright! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is vague and generic, using the non-descriptive term 'fix' without clarifying which Windows issues are being addressed or what the specific changes accomplish. Revise the title to be more specific and descriptive, such as 'Fix Windows-specific error handling in mmap, winapi, errno, and sys modules' to clearly convey the scope and nature of the changes.
✅ 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 unit tests (beta)
  • Create PR with unit tests

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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone force-pushed the win-issues branch 2 times, most recently from aaf925a to 68a394f Compare March 20, 2026 12:33
youknowone added 7 commits March 20, 2026 22:48
@youknowone
Disallow instantiation of sys.getwindowsversion type
86a96e7
Add slot_new to PyWindowsVersion that raises TypeError,
matching sys.flags behavior.
@youknowone
Remove incorrect WSAHOS errno constant
b02cdb6
WSAHOS was hardcoded as an alias for WSAHOST_NOT_FOUND, but
CPython guards it with #ifdef WSAHOS which doesn't exist in
modern Windows SDK headers.
@youknowone
Fix mmap resize to raise OSError instead of SystemError
d7d6f7a
@youknowone
Fix CreateProcess with empty environment on Windows
24a1719
Empty env dict produced a single null terminator, but
CreateProcessW requires a double null for a valid empty
environment block.
@youknowone
Revert mmap resize error to SystemError and fix errno.rs formatting
acb11da
mmap resize raises SystemError (not OSError) when mremap is unavailable,
matching CPython behavior. test_mmap catches SystemError to skip unsupported
resize operations.
@youknowone
Fix named mmap resize to raise OSError and unmark test_sleep expected…
30e19cd
…Failure

Named mmap resize on Windows should raise OSError (not SystemError).
Remove expectedFailure mark from TimeEINTRTest.test_sleep as it now passes.
@youknowone
Use expectedFailureIf for TimeEINTRTest.test_sleep on Linux
8b8caca
test_sleep passes on macOS but fails on Linux due to timing.
@youknowone
youknowone force-pushed the win-issues branch from 68a394f to 8b8caca Compare March 20, 2026 13:48
@youknowone
Remove expectedFailure for TimeEINTRTest.test_sleep
de0db04
test_sleep now passes on all platforms.
@youknowone
youknowone marked this pull request as ready for review March 21, 2026 00:46
coderabbitai[bot]
coderabbitai Bot reviewed Mar 21, 2026
View reviewed changes

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/vm/src/stdlib/_winapi.rs (1)

425-429: ⚠️ Potential issue | 🔴 Critical

Fix UTF-8 slicing on environment variable names to prevent panics.

Line 428 uses byte-level slicing k[1..] on a UTF-8 &str. When an environment variable name starts with a multi-byte character (e.g., Ä=value), Rust panics because the slice index 1 lands in the middle of the multi-byte sequence rather than at a valid UTF-8 boundary. This crashes the VM instead of raising ValueError.

Suggested fix
-            if k.is_empty() || k[1..].contains('=') {
+            if k.is_empty() || k.chars().skip(1).any(|ch| ch == '=') {
                 return Err(vm.new_value_error("illegal environment variable name"));
             }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/stdlib/_winapi.rs` around lines 425 - 429, The code currently
slices the UTF-8 string k with k[1..], which can panic for multi-byte
characters; replace the byte-slice check with a char-aware check such as using
k.chars().skip(1).any(|c| c == '=') so the condition becomes if k.is_empty() ||
k.chars().skip(1).any(|c| c == '=') { return Err(vm.new_value_error("illegal
environment variable name")); } to avoid UTF-8 boundary panics while keeping the
same semantics for k and v validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/stdlib/errno.rs`:
- Around line 42-46: The errno module is missing the Windows constant
WSAHOST_NOT_FOUND in its exported WSA error list; update the export list in
crates/vm/src/stdlib/errno.rs by replacing the placeholder/TODO (WSAHOS) with
the full constant name WSAHOST_NOT_FOUND so the module exposes that constant
(used by crates/stdlib/src/socket.rs for EAI mapping).

---

Outside diff comments:
In `@crates/vm/src/stdlib/_winapi.rs`:
- Around line 425-429: The code currently slices the UTF-8 string k with k[1..],
which can panic for multi-byte characters; replace the byte-slice check with a
char-aware check such as using k.chars().skip(1).any(|c| c == '=') so the
condition becomes if k.is_empty() || k.chars().skip(1).any(|c| c == '=') {
return Err(vm.new_value_error("illegal environment variable name")); } to avoid
UTF-8 boundary panics while keeping the same semantics for k and v validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 6d320c3e-6392-41ac-9255-594c41d0ab3e

📥 Commits

Reviewing files that changed from the base of the PR and between 38f742a and de0db04.

⛔ Files ignored due to path filters (3)
  • Lib/test/test_mmap.py is excluded by !Lib/**
  • Lib/test/test_subprocess.py is excluded by !Lib/**
  • Lib/test/test_sys.py is excluded by !Lib/**
📒 Files selected for processing (4)
  • crates/stdlib/src/mmap.rs
  • crates/vm/src/stdlib/_winapi.rs
  • crates/vm/src/stdlib/errno.rs
  • crates/vm/src/stdlib/sys.rs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread crates/vm/src/stdlib/errno.rs
Comment on lines +42 to +46
WSAESTALE, WSAETIMEDOUT, WSAETOOMANYREFS, WSAEUSERS, WSAEWOULDBLOCK, WSAID_ACCEPTEX,
WSAID_CONNECTEX, WSAID_DISCONNECTEX, WSAID_GETACCEPTEXSOCKADDRS, WSAID_TRANSMITFILE,
WSAID_TRANSMITPACKETS, WSAID_WSAPOLL, WSAID_WSARECVMSG, WSANO_DATA, WSANO_RECOVERY,
WSANOTINITIALISED, WSAPROTOCOL_LEN, WSASERVICE_NOT_FOUND, WSASYS_STATUS_LEN,
WSASYSCALLFAILURE, WSASYSNOTREADY, WSATRY_AGAIN, WSATYPE_NOT_FOUND, WSAVERNOTSUPPORTED,

@coderabbitai coderabbitai Bot Mar 21, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's examine the errno.rs file at the specified lines to see the current state
wc -l crates/vm/src/stdlib/errno.rs

Repository: RustPython/RustPython

Length of output: 98


🏁 Script executed:

# Check what's at lines 42-46 in errno.rs
sed -n '40,50p' crates/vm/src/stdlib/errno.rs

Repository: RustPython/RustPython

Length of output: 785


🏁 Script executed:

# Check what's at line 566 in errno.rs
sed -n '560,575p' crates/vm/src/stdlib/errno.rs

Repository: RustPython/RustPython

Length of output: 665


🏁 Script executed:

# Search for WSAHOST_NOT_FOUND in the codebase
rg "WSAHOST_NOT_FOUND" --type rust

Repository: RustPython/RustPython

Length of output: 170


🏁 Script executed:

# Check socket.rs around lines 85-95 for the claimed usage
sed -n '80,100p' crates/stdlib/src/socket.rs

Repository: RustPython/RustPython

Length of output: 1371


🏁 Script executed:

# Check if WSAHOS is defined or referenced elsewhere
rg "WSAHOS" --type rust -B2 -A2

Repository: RustPython/RustPython

Length of output: 888


🏁 Script executed:

# Check broader context around the TODO at line 566
sed -n '560,575p' crates/vm/src/stdlib/errno.rs

Repository: RustPython/RustPython

Length of output: 665


🏁 Script executed:

# Look at the import statements at the top of errno.rs to understand the Windows socket setup
sed -n '1,50p' crates/vm/src/stdlib/errno.rs | head -40

Repository: RustPython/RustPython

Length of output: 1695


🏁 Script executed:

# Check if there are any comments explaining why WSAHOST_NOT_FOUND was removed
rg -B5 -A5 "WSAHOST_NOT_FOUND|WSAHOS" crates/vm/src/stdlib/errno.rs

Repository: RustPython/RustPython

Length of output: 468


Add WSAHOST_NOT_FOUND to the errno module's Windows error exports.

errno no longer exposes WSAHOST_NOT_FOUND at the module level, even though it's a standard Winsock error code used in crates/stdlib/src/socket.rs for EAI mapping. While socket.rs imports this constant directly from windows_sys, the omission leaves the errno module incomplete on Windows. Replace the WSAHOS TODO comment with the correct full constant name.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/vm/src/stdlib/errno.rs` around lines 42 - 46, The errno module is
missing the Windows constant WSAHOST_NOT_FOUND in its exported WSA error list;
update the export list in crates/vm/src/stdlib/errno.rs by replacing the
placeholder/TODO (WSAHOS) with the full constant name WSAHOST_NOT_FOUND so the
module exposes that constant (used by crates/stdlib/src/socket.rs for EAI
mapping).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@youknowone
youknowone merged commit 2d676e7 into RustPython:main Mar 21, 2026
19 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@youknowone
youknowone deleted the win-issues branch March 21, 2026 13:49
Copilot AI pushed a commit that referenced this pull request Mar 25, 2026
@youknowone
A few windows fix (#7458)
b26f013
* Disallow instantiation of sys.getwindowsversion type

Add slot_new to PyWindowsVersion that raises TypeError,
matching sys.flags behavior.

* Remove incorrect WSAHOS errno constant

WSAHOS was hardcoded as an alias for WSAHOST_NOT_FOUND, but
CPython guards it with #ifdef WSAHOS which doesn't exist in
modern Windows SDK headers.

* Fix mmap resize to raise OSError instead of SystemError

* Fix CreateProcess with empty environment on Windows

Empty env dict produced a single null terminator, but
CreateProcessW requires a double null for a valid empty
environment block.

* Revert mmap resize error to SystemError and fix errno.rs formatting

mmap resize raises SystemError (not OSError) when mremap is unavailable,
matching CPython behavior. test_mmap catches SystemError to skip unsupported
resize operations.

* Fix named mmap resize to raise OSError and unmark test_sleep expectedFailure

Named mmap resize on Windows should raise OSError (not SystemError).
Remove expectedFailure mark from TimeEINTRTest.test_sleep as it now passes.

* Use expectedFailureIf for TimeEINTRTest.test_sleep on Linux

test_sleep passes on macOS but fails on Linux due to timing.

* Remove expectedFailure for TimeEINTRTest.test_sleep

test_sleep now passes on all platforms.
youknowone added a commit that referenced this pull request Sep 16, 2026
@youknowone
A few windows fix (#7458)
364a7d5
* Disallow instantiation of sys.getwindowsversion type

Add slot_new to PyWindowsVersion that raises TypeError,
matching sys.flags behavior.

* Remove incorrect WSAHOS errno constant

WSAHOS was hardcoded as an alias for WSAHOST_NOT_FOUND, but
CPython guards it with #ifdef WSAHOS which doesn't exist in
modern Windows SDK headers.

* Fix mmap resize to raise OSError instead of SystemError

* Fix CreateProcess with empty environment on Windows

Empty env dict produced a single null terminator, but
CreateProcessW requires a double null for a valid empty
environment block.

* Revert mmap resize error to SystemError and fix errno.rs formatting

mmap resize raises SystemError (not OSError) when mremap is unavailable,
matching CPython behavior. test_mmap catches SystemError to skip unsupported
resize operations.

* Fix named mmap resize to raise OSError and unmark test_sleep expectedFailure

Named mmap resize on Windows should raise OSError (not SystemError).
Remove expectedFailure mark from TimeEINTRTest.test_sleep as it now passes.

* Use expectedFailureIf for TimeEINTRTest.test_sleep on Linux

test_sleep passes on macOS but fails on Linux due to timing.

* Remove expectedFailure for TimeEINTRTest.test_sleep

test_sleep now passes on all platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@coderabbitai coderabbitai[bot] coderabbitai[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@youknowone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.