Skip to content
Prev Previous commit
Next Next commit
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.
  • Loading branch information
youknowone committed Mar 20, 2026
commit acb11da89915717a6977c223d95659c025d515a0
4 changes: 2 additions & 2 deletions crates/stdlib/src/mmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,7 @@ mod mmap {
fn resize(&self, _newsize: PyIntRef, vm: &VirtualMachine) -> PyResult<()> {
self.check_resizeable(vm)?;
// TODO: implement using mremap on Linux
Err(vm.new_os_error("mmap: resizing not available--no mremap()"))
Err(vm.new_system_error("mmap: resizing not available--no mremap()"))
}

#[cfg(windows)]
Expand All @@ -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_os_error("mmap: cannot resize a named memory mapping"));
return Err(vm.new_system_error("mmap: cannot resize a named memory mapping"));
}

let is_anonymous = handle == INVALID_HANDLE_VALUE as isize;
Expand Down
11 changes: 5 additions & 6 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,
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 Down