Skip to content

Commit b26f013

Browse files
youknowoneCopilot
authored andcommitted
A few windows fix (#7458)
* 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.
1 parent d061822 commit b26f013

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

Lib/test/test_mmap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,6 @@ def test_resize_fails_if_mapping_held_elsewhere(self):
867867
finally:
868868
f.close()
869869

870-
@unittest.expectedFailure # TODO: RUSTPYTHON
871870
@unittest.skipUnless(os.name == 'nt', 'requires Windows')
872871
def test_resize_succeeds_with_error_for_second_named_mapping(self):
873872
"""If a more than one mapping exists of the same name, none of them can

Lib/test/test_subprocess.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,6 @@ def test_run_with_pathlike_path_and_arguments(self):
19031903
res = subprocess.run(args)
19041904
self.assertEqual(res.returncode, 57)
19051905

1906-
@unittest.skipIf(mswindows, "TODO: RUSTPYTHON; empty env block fails nondeterministically")
19071906
@unittest.skipUnless(mswindows, "Maybe test trigger a leak on Ubuntu")
19081907
def test_run_with_an_empty_env(self):
19091908
# gh-105436: fix subprocess.run(..., env={}) broken on Windows

Lib/test/test_sys.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ def test_sys_flags_no_instantiation(self):
878878
def test_sys_version_info_no_instantiation(self):
879879
self.assert_raise_on_new_sys_type(sys.version_info)
880880

881-
@unittest.expectedFailure # TODO: RUSTPYTHON; TypeError not raised for getwindowsversion instantiation
882881
def test_sys_getwindowsversion_no_instantiation(self):
883882
# Skip if not being run on Windows.
884883
test.support.get_attribute(sys, "getwindowsversion")

crates/stdlib/src/mmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ mod mmap {
12041204

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

12101210
let is_anonymous = handle == INVALID_HANDLE_VALUE as isize;

crates/vm/src/stdlib/_winapi.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ mod _winapi {
445445
for (_, entry) in entries {
446446
out.push(entry);
447447
}
448+
// Each entry ends with \0, so one more \0 terminates the block.
449+
// For empty env, we need \0\0 as a valid empty environment block.
450+
if out.is_empty() {
451+
out.push_str("\0");
452+
}
448453
out.push_str("\0");
449454
Ok(out.into_vec())
450455
}

crates/vm/src/stdlib/errno.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ pub mod errors {
3939
WSAENOMORE, WSAENOPROTOOPT, WSAENOTCONN, WSAENOTEMPTY, WSAENOTSOCK, WSAEOPNOTSUPP,
4040
WSAEPFNOSUPPORT, WSAEPROCLIM, WSAEPROTONOSUPPORT, WSAEPROTOTYPE,
4141
WSAEPROVIDERFAILEDINIT, WSAEREFUSED, WSAEREMOTE, WSAESHUTDOWN, WSAESOCKTNOSUPPORT,
42-
WSAESTALE, WSAETIMEDOUT, WSAETOOMANYREFS, WSAEUSERS, WSAEWOULDBLOCK, WSAHOST_NOT_FOUND,
43-
WSAID_ACCEPTEX, WSAID_CONNECTEX, WSAID_DISCONNECTEX, WSAID_GETACCEPTEXSOCKADDRS,
44-
WSAID_TRANSMITFILE, WSAID_TRANSMITPACKETS, WSAID_WSAPOLL, WSAID_WSARECVMSG, WSANO_DATA,
45-
WSANO_RECOVERY, WSANOTINITIALISED, WSAPROTOCOL_LEN, WSASERVICE_NOT_FOUND,
46-
WSASYS_STATUS_LEN, WSASYSCALLFAILURE, WSASYSNOTREADY, WSATRY_AGAIN, WSATYPE_NOT_FOUND,
47-
WSAVERNOTSUPPORTED,
42+
WSAESTALE, WSAETIMEDOUT, WSAETOOMANYREFS, WSAEUSERS, WSAEWOULDBLOCK, WSAID_ACCEPTEX,
43+
WSAID_CONNECTEX, WSAID_DISCONNECTEX, WSAID_GETACCEPTEXSOCKADDRS, WSAID_TRANSMITFILE,
44+
WSAID_TRANSMITPACKETS, WSAID_WSAPOLL, WSAID_WSARECVMSG, WSANO_DATA, WSANO_RECOVERY,
45+
WSANOTINITIALISED, WSAPROTOCOL_LEN, WSASERVICE_NOT_FOUND, WSASYS_STATUS_LEN,
46+
WSASYSCALLFAILURE, WSASYSNOTREADY, WSATRY_AGAIN, WSATYPE_NOT_FOUND, WSAVERNOTSUPPORTED,
4847
},
4948
};
5049
#[cfg(windows)]
@@ -64,8 +63,6 @@ pub mod errors {
6463
ETIMEDOUT, ETOOMANYREFS, EUSERS, EWOULDBLOCK,
6564
// TODO: EBADF should be here once winerrs are translated to errnos but it messes up some things atm
6665
}
67-
#[cfg(windows)]
68-
pub const WSAHOS: i32 = WSAHOST_NOT_FOUND;
6966
}
7067

7168
#[cfg(any(unix, windows, target_os = "wasi"))]
@@ -566,7 +563,7 @@ const ERROR_CODES: &[(&str, i32)] = &[
566563
e!(cfg(windows), WSAEDISCON),
567564
e!(cfg(windows), WSAEINTR),
568565
e!(cfg(windows), WSAEPROTOTYPE),
569-
e!(cfg(windows), WSAHOS),
566+
// TODO: e!(cfg(windows), WSAHOS),
570567
e!(cfg(windows), WSAEADDRINUSE),
571568
e!(cfg(windows), WSAEADDRNOTAVAIL),
572569
e!(cfg(windows), WSAEALREADY),

crates/vm/src/stdlib/sys.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,12 @@ mod sys {
18071807

18081808
#[cfg(windows)]
18091809
#[pyclass(with(PyStructSequence))]
1810-
impl PyWindowsVersion {}
1810+
impl PyWindowsVersion {
1811+
#[pyslot]
1812+
fn slot_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
1813+
Err(vm.new_type_error("cannot create 'sys.getwindowsversion' instances"))
1814+
}
1815+
}
18111816

18121817
#[derive(Debug)]
18131818
#[pystruct_sequence_data(try_from_object)]

0 commit comments

Comments
 (0)