Skip to content
Merged
1 change: 0 additions & 1 deletion Lib/test/test_mmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,6 @@ def test_resize_fails_if_mapping_held_elsewhere(self):
finally:
f.close()

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.skipUnless(os.name == 'nt', 'requires Windows')
def test_resize_succeeds_with_error_for_second_named_mapping(self):
"""If a more than one mapping exists of the same name, none of them can
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,6 @@ def test_run_with_pathlike_path_and_arguments(self):
res = subprocess.run(args)
self.assertEqual(res.returncode, 57)

@unittest.skipIf(mswindows, "TODO: RUSTPYTHON; empty env block fails nondeterministically")
@unittest.skipUnless(mswindows, "Maybe test trigger a leak on Ubuntu")
def test_run_with_an_empty_env(self):
# gh-105436: fix subprocess.run(..., env={}) broken on Windows
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,6 @@ def test_sys_flags_no_instantiation(self):
def test_sys_version_info_no_instantiation(self):
self.assert_raise_on_new_sys_type(sys.version_info)

@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError not raised for getwindowsversion instantiation
def test_sys_getwindowsversion_no_instantiation(self):
# Skip if not being run on Windows.
test.support.get_attribute(sys, "getwindowsversion")
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ mod mmap {

// Check if this is a Named mmap - these cannot be resized
if let Some(MmapObj::Named(_)) = mmap_guard.as_ref() {
return Err(vm.new_system_error("mmap: cannot resize a named memory mapping"));
return Err(vm.new_os_error("mmap: cannot resize a named memory mapping"));
}

let is_anonymous = handle == INVALID_HANDLE_VALUE as isize;
Expand Down
5 changes: 5 additions & 0 deletions crates/vm/src/stdlib/_winapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ mod _winapi {
for (_, entry) in entries {
out.push(entry);
}
// Each entry ends with \0, so one more \0 terminates the block.
// For empty env, we need \0\0 as a valid empty environment block.
if out.is_empty() {
out.push_str("\0");
}
out.push_str("\0");
Ok(out.into_vec())
}
Expand Down
15 changes: 6 additions & 9 deletions crates/vm/src/stdlib/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,11 @@ pub mod errors {
WSAENOMORE, WSAENOPROTOOPT, WSAENOTCONN, WSAENOTEMPTY, WSAENOTSOCK, WSAEOPNOTSUPP,
WSAEPFNOSUPPORT, WSAEPROCLIM, WSAEPROTONOSUPPORT, WSAEPROTOTYPE,
WSAEPROVIDERFAILEDINIT, WSAEREFUSED, WSAEREMOTE, WSAESHUTDOWN, WSAESOCKTNOSUPPORT,
WSAESTALE, WSAETIMEDOUT, WSAETOOMANYREFS, WSAEUSERS, WSAEWOULDBLOCK, WSAHOST_NOT_FOUND,
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,
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,
Comment on lines +42 to +46
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.

⚠️ 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).

},
};
#[cfg(windows)]
Expand All @@ -64,8 +63,6 @@ pub mod errors {
ETIMEDOUT, ETOOMANYREFS, EUSERS, EWOULDBLOCK,
// TODO: EBADF should be here once winerrs are translated to errnos but it messes up some things atm
}
#[cfg(windows)]
pub const WSAHOS: i32 = WSAHOST_NOT_FOUND;
}

#[cfg(any(unix, windows, target_os = "wasi"))]
Expand Down Expand Up @@ -566,7 +563,7 @@ const ERROR_CODES: &[(&str, i32)] = &[
e!(cfg(windows), WSAEDISCON),
e!(cfg(windows), WSAEINTR),
e!(cfg(windows), WSAEPROTOTYPE),
e!(cfg(windows), WSAHOS),
// TODO: e!(cfg(windows), WSAHOS),
e!(cfg(windows), WSAEADDRINUSE),
e!(cfg(windows), WSAEADDRNOTAVAIL),
e!(cfg(windows), WSAEALREADY),
Expand Down
7 changes: 6 additions & 1 deletion crates/vm/src/stdlib/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,12 @@ mod sys {

#[cfg(windows)]
#[pyclass(with(PyStructSequence))]
impl PyWindowsVersion {}
impl PyWindowsVersion {
#[pyslot]
fn slot_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
Err(vm.new_type_error("cannot create 'sys.getwindowsversion' instances"))
}
}

#[derive(Debug)]
#[pystruct_sequence_data(try_from_object)]
Expand Down
Loading