8000 fix windows OSError · RustPython/RustPython@6c4ee95 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c4ee95

Browse files
committed
fix windows OSError
1 parent f0f4633 commit 6c4ee95

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

Lib/test/test_subprocess.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,6 @@ def test_handles_closed_on_exception(self):
14651465
self.assertFalse(os.path.exists(ofname))
14661466
self.assertFalse(os.path.exists(efname))
14671467

1468-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
14691468
def test_communicate_epipe(self):
14701469
# Issue 10963: communicate() should hide EPIPE
14711470
p = subprocess.Popen(ZERO_RETURN_CMD,
@@ -1496,7 +1495,6 @@ def test_repr(self):
14961495
p.returncode = code
14971496
self.assertEqual(repr(p), sx)
14981497

1499-
@unittest.expectedFailureIfWindows("TODO: RUSTPYTHON")
15001498
def test_communicate_epipe_only_stdin(self):
15011499
# Issue 10963: communicate() should hide EPIPE
15021500
p = subprocess.Popen(ZERO_RETURN_CMD,

vm/src/exceptions.rs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,8 @@ pub(crate) fn raw_os_error_to_exc_type(
10191019
) -> Option<&'static Py<PyType>> {
10201020
use crate::stdlib::errno::errors;
10211021
let excs = &vm.ctx.exceptions;
1022+
#[cfg(windows)]
1023+
let errno = win_error_to_errno(errno as u32);
10221024
match errno {
10231025
errors::EWOULDBLOCK => Some(excs.blocking_io_error),
10241026
errors::EALREADY => Some(excs.blocking_io_error),
@@ -1043,6 +1045,106 @@ pub(crate) fn raw_os_error_to_exc_type(
10431045
}
10441046
}
10451047

1048+
#[cfg(windows)]
1049+
pub(crate) fn win_error_to_errno(winerror: u32) -> i32 {
1050+
use crate::stdlib::errno::errors;
1051+
use windows_sys::Win32::Foundation::*;
1052+
// Unwrap FACILITY_WIN32 HRESULT errors.
1053+
// if ((winerror & 0xFFFF0000) == 0x80070000) {
1054+
// winerror &= 0x0000FFFF;
1055+
// }
1056+
1057+
// Winsock error codes (10000-11999) are errno values.
1058+
// if winerror >= 10000 && winerror < 12000 {
1059+
// match winerror {
1060+
// WSAEINTR | WSAEBADF | WSAEACCES | WSAEFAULT | WSAEINVAL | WSAEMFILE => {
1061+
// // Winsock definitions of errno values. See WinSock2.h
1062+
// return winerror - 10000;
1063+
// },
1064+
// _ => return winerror,
1065+
// }
1066+
// }
1067+
1068+
#[allow(non_upper_case_globals)]
1069+
match winerror {
1070+
ERROR_FILE_NOT_FOUND
1071+
| ERROR_PATH_NOT_FOUND
1072+
| ERROR_INVALID_DRIVE
1073+
| ERROR_NO_MORE_FILES
1074+
| ERROR_BAD_NETPATH
1075+
| ERROR_BAD_NET_NAME
1076+
| ERROR_BAD_PATHNAME
1077+
| ERROR_FILENAME_EXCED_RANGE => errors::ENOENT,
1078+
ERROR_BAD_ENVIRONMENT => errors::E2BIG,
1079+
ERROR_BAD_FORMAT
1080+
| ERROR_INVALID_STARTING_CODESEG
1081+
| ERROR_INVALID_STACKSEG
1082+
| ERROR_INVALID_MODULETYPE
1083+
| ERROR_INVALID_EXE_SIGNATURE
1084+
| ERROR_EXE_MARKED_INVALID
1085+
| ERROR_BAD_EXE_FORMAT
1086+
| ERROR_ITERATED_DATA_EXCEEDS_64k
1087+
| ERROR_INVALID_MINALLOCSIZE
1088+
| ERROR_DYNLINK_FROM_INVALID_RING
1089+
| ERROR_IOPL_NOT_ENABLED
1090+
| ERROR_INVALID_SEGDPL
1091+
| ERROR_AUTODATASEG_EXCEEDS_64k
1092+
| ERROR_RING2SEG_MUST_BE_MOVABLE
1093+
| ERROR_RELOC_CHAIN_XEEDS_SEGLIM
1094+
| ERROR_INFLOOP_IN_RELOC_CHAIN => errors::ENOEXEC,
1095+
ERROR_INVALID_HANDLE | ERROR_INVALID_TARGET_HANDLE | ERROR_DIRECT_ACCESS_HANDLE => {
1096+
errors::EBADF
1097+
}
1098+
ERROR_WAIT_NO_CHILDREN | ERROR_CHILD_NOT_COMPLETE => errors::ECHILD,
1099+
ERROR_NO_PROC_SLOTS | ERROR_MAX_THRDS_REACHED | ERROR_NESTING_NOT_ALLOWED => errors::EAGAIN,
1100+
ERROR_ARENA_TRASHED
1101+
| ERROR_NOT_ENOUGH_MEMORY
1102+
| ERROR_INVALID_BLOCK
1103+
| ERROR_NOT_ENOUGH_QUOTA => errors::ENOMEM,
1104+
ERROR_ACCESS_DENIED
1105+
| ERROR_CURRENT_DIRECTORY
1106+
| ERROR_WRITE_PROTECT
1107+
| ERROR_BAD_UNIT
1108+
| ERROR_NOT_READY
1109+
| ERROR_BAD_COMMAND
1110+
| ERROR_CRC
1111+
| ERROR_BAD_LENGTH
1112+
| ERROR_SEEK
1113+
| ERROR_NOT_DOS_DISK
1114+
| ERROR_SECTOR_NOT_FOUND
1115+
| ERROR_OUT_OF_PAPER
1116+
| ERROR_WRITE_FAULT
1117+
| ERROR_READ_FAULT
1118+
| ERROR_GEN_FAILURE
1119+
| ERROR_SHARING_VIOLATION
1120+
| ERROR_LOCK_VIOLATION
1121+
| ERROR_WRONG_DISK
1122+
| ERROR_SHARING_BUFFER_EXCEEDED
1123+
| ERROR_NETWORK_ACCESS_DENIED
1124+
| ERROR_CANNOT_MAKE
1125+
| ERROR_FAIL_I24
1126+
| ERROR_DRIVE_LOCKED
1127+
| ERROR_SEEK_ON_DEVICE
1128+
| ERROR_NOT_LOCKED
1129+
| ERROR_LOCK_FAILED
1130+
| 35 => errors::EACCES,
1131+
ERROR_FILE_EXISTS | ERROR_ALREADY_EXISTS => errors::EEXIST,
1132+
ERROR_NOT_SAME_DEVICE => errors::EXDEV,
1133+
ERROR_DIRECTORY => errors::ENOTDIR,
1134+
ERROR_TOO_MANY_OPEN_FILES => errors::EMFILE,
1135+
ERROR_DISK_FULL => errors::ENOSPC,
1136+
ERROR_BROKEN_PIPE | ERROR_NO_DATA => errors::EPIPE,
1137+
ERROR_DIR_NOT_EMPTY => errors::ENOTEMPTY,
1138+
ERROR_NO_UNICODE_TRANSLATION => errors::EILSEQ,
1139+
ERROR_INVALID_FUNCTION
1140+
| ERROR_INVALID_ACCESS
1141+
| ERROR_INVALID_DATA
1142+
| ERROR_INVALID_PARAMETER
1143+ 6152
| ERROR_NEGATIVE_SEEK => errors::EINVAL,
1144+
_ => errors::EINVAL,
1145+
}
1146+
}
1147+
10461148
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
10471149
pub(crate) fn raw_os_error_to_exc_type(
10481150
_errno: i32,

0 commit comments

Comments
 (0)
0