Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d540bee
Make OSError subclass instead of itself
ChJR Aug 23, 2021
041c2c3
Differentiate making OSError and its subclasses
ChJR Aug 24, 2021
65fba63
Enable matched test
ChJR Aug 24, 2021
3059bbd
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Aug 25, 2021
b9bdaba
Add Windows specific errno OSError subclasses
ChJR Aug 26, 2021
6eb77ed
Remove OSError specific macro
ChJR Aug 26, 2021
41e8b31
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Aug 26, 2021
58ba136
Fix CI build error on Windows
ChJR Aug 26, 2021
8ccdef9
Avoid CI build error on WASI
ChJR Aug 28, 2021
9a28183
Use wasmer_wasi on WASI to handle errno
ChJR Aug 28, 2021
cf61513
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Aug 28, 2021
27d8b5f
Fix typo
ChJR Aug 28, 2021
18a80a8
Fix typo again
ChJR Aug 28, 2021
84bc910
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Sep 18, 2021
0354a71
Refine OSError.__new__
ChJR Sep 18, 2021
9250caa
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Sep 25, 2021
5a06415
Avoid test failures
ChJR Sep 25, 2021
15877d9
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 2, 2021
4129d74
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 2, 2021
3ff1025
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 2, 2021
1e38c17
Avoid CI error
ChJR Oct 2, 2021
2cb27d0
Revert Avoid CI error
ChJR Oct 2, 2021
aeeadb1
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 3, 2021
124cc27
Use crate::stdlib::errno::errors instead of implementing all constants
ChJR Oct 3, 2021
b90d12a
Remove unused wasmer_wasi on WASI
ChJR Oct 4, 2021
f2fff18
Move 'use crate::stdlib::errno::errors' to proper place
ChJR Oct 4, 2021
ea5cdf2
Use direct methods rather than wrapper methods
ChJR Oct 5, 2021
e0d88ed
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 5, 2021
fa1718b
Add errnos on WASI
ChJR Oct 5, 2021
02946e8
Remove cfg over crate::stdlib::errno:errors module
ChJR Oct 5, 2021
73795e8
Add errno::errors on other platforms
ChJR Oct 6, 2021
a23101b
Merge branch 'main' into feature/OSError-Subclass-Ctor
ChJR Oct 6, 2021
2572890
Avoid CI build error
ChJR Oct 6, 2021
a504a74
Avoid WASI build error by not using errno::errors
ChJR Oct 6, 2021
38426fb
Revert "Add errno::errors on other platforms"
ChJR Oct 7, 2021
179df68
Revert "Remove cfg over crate::stdlib::errno:errors module"
ChJR Oct 7, 2021
d913c45
Avoid CI build error on WASI
ChJR Oct 7, 2021
7f8562a
remove meaningless relocation
youknowone Oct 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_exception_hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ def _make_map(s):
return _map
_map = _make_map(_pep_map)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_errno_mapping(self):
# The OSError constructor maps errnos to subclasses
# A sample test for the basic functionality
Expand Down
22 changes: 0 additions & 22 deletions Lib/test/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ def test_executable_takes_precedence(self):
self._assert_python, pre_args,
executable=NONEXISTING_CMD[0])

# TODO: RUSTPYTHON
if sys.platform != "win32":
test_executable_takes_precedence = unittest.expectedFailure(test_executable_takes_precedence)

@unittest.skipIf(mswindows, "executable argument replaces shell")
def test_executable_replaces_shell(self):
# Check that the executable argument replaces the default shell
Expand Down Expand Up @@ -431,8 +427,6 @@ def test_cwd_with_pathlike(self):
temp_dir = self._normalize_cwd(temp_dir)
self._assert_cwd(temp_dir, sys.executable, cwd=FakePath(temp_dir))

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.skipIf(mswindows, "pending resolution of issue #15533")
def test_cwd_with_relative_arg(self):
# Check that Popen looks for args[0] relative to cwd if args[0]
Expand All @@ -449,8 +443,6 @@ def test_cwd_with_relative_arg(self):
python_dir = self._normalize_cwd(python_dir)
self._assert_cwd(python_dir, rel_python, cwd=python_dir)

# TODO: RUSTPYTHON
@unittest.expectedFailure
@unittest.skipIf(mswindows, "pending resolution of issue #15533")
def test_cwd_with_relative_executable(self):
# Check that Popen looks for executable relative to cwd if executable
Expand Down Expand Up @@ -484,10 +476,6 @@ def test_cwd_with_absolute_arg(self):
wrong_dir = self._normalize_cwd(wrong_dir)
self._assert_cwd(wrong_dir, abs_python, cwd=wrong_dir)

# TODO: RUSTPYTHON
if sys.platform != "win32":
test_cwd_with_absolute_arg = unittest.expectedFailure(test_cwd_with_absolute_arg)

@unittest.skipIf(sys.base_prefix != sys.prefix,
'Test is not venv-compatible')
def test_executable_with_cwd(self):
Expand Down Expand Up @@ -1257,10 +1245,6 @@ def test_leaking_fds_on_error(self):
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)

# TODO: RUSTPYTHON
if sys.platform != "win32":
test_leaking_fds_on_error = unittest.expectedFailure(test_leaking_fds_on_error)

def test_nonexisting_with_pipes(self):
# bpo-30121: Popen with pipes must close properly pipes on error.
# Previously, os.close() was called with a Windows handle which is not
Expand Down Expand Up @@ -1755,8 +1739,6 @@ class PopenNoDestructor(subprocess.Popen):
def __del__(self):
pass

# TODO: RUSTPYTHON
@unittest.expectedFailure
@mock.patch("subprocess._posixsubprocess.fork_exec")
def test_exception_errpipe_normal(self, fork_exec):
"""Test error passing done through errpipe_write in the good case"""
Expand Down Expand Up @@ -3513,10 +3495,6 @@ def test_invalid_args(self):
stderr=subprocess.PIPE) as proc:
pass

# TODO: RUSTPYTHON
if sys.platform != "win32":
test_invalid_args = unittest.expectedFailure(test_invalid_args)

def test_broken_pipe_cleanup(self):
"""Broken pipe error should not prevent wait() (Issue 21619)"""
proc = subprocess.Popen(ZERO_RETURN_CMD,
Expand Down
91 changes: 87 additions & 4 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,10 @@ impl<C: widestring::UChar> IntoPyException for widestring::NulError<C> {
pub(super) mod types {
use crate::common::lock::PyRwLock;
use crate::{
builtins::{traceback::PyTracebackRef, PyTupleRef, PyTypeRef},
function::FuncArgs,
PyRef, PyResult, VirtualMachine,
builtins::{traceback::PyTracebackRef, PyInt, PyTupleRef, PyTypeRef},
exceptions::invoke,
function::{FuncArgs, IntoPyResult},
PyObjectRef, PyRef, PyResult, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;

Expand Down Expand Up @@ -1146,8 +1147,90 @@ pub(super) mod types {
PyOSError,
PyException,
os_error,
"Base class for I/O related errors."
"Base class for I/O related errors.",
os_error_new,
base_exception_init,
}
#[cfg(not(target_arch = "wasm32"))]
fn os_error_optional_new(
args: Vec<PyObjectRef>,
vm: &VirtualMachine,
) -> Option<PyResult<PyBaseExceptionRef>> {
use crate::stdlib::errno::errors;

let len = args.len();
if len >= 2 {
let args = args.as_slice();
let errno = &args[0];
let error = match errno.payload_if_subclass::<PyInt>(vm) {
Some(errno) => match errno.try_to_primitive::<i32>(vm) {
Ok(errno) => {
let excs = &vm.ctx.exceptions;
let error = match errno {
errors::EWOULDBLOCK => Some(excs.blocking_io_error.clone()),
errors::EALREADY => Some(excs.blocking_io_error.clone()),
errors::EINPROGRESS => Some(excs.blocking_io_error.clone()),
errors::EPIPE => Some(excs.broken_pipe_error.clone()),
errors::ESHUTDOWN => Some(excs.broken_pipe_error.clone()),
errors::ECHILD => Some(excs.child_process_error.clone()),
errors::ECONNABORTED => Some(excs.connection_aborted_error.clone()),
errors::ECONNREFUSED => Some(excs.connection_refused_error.clone()),
errors::ECONNRESET => Some(excs.connection_reset_error.clone()),
errors::EEXIST => Some(excs.file_exists_error.clone()),
errors::ENOENT => Some(excs.file_not_found_error.clone()),
errors::EISDIR => Some(excs.is_a_directory_error.clone()),
errors::ENOTDIR => Some(excs.not_a_directory_error.clone()),
errors::EINTR => Some(excs.interrupted_error.clone()),
errors::EACCES => Some(excs.permission_error.clone()),
errors::EPERM => Some(excs.permission_error.clone()),
errors::ESRCH => Some(excs.process_lookup_error.clone()),
errors::ETIMEDOUT => Some(excs.timeout_error.clone()),
_ => None,
};

if error.is_some() {
Some(invoke(error?, args.to_vec(), vm))
} else {
None
}
}
Err(_) => None,
},
None => None,
};

error
} else {
None
}
}
#[cfg(not(target_arch = "wasm32"))]
fn os_error_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
// We need this method, because of how `CPython` copies `init`
// from `BaseException` in `SimpleExtendsException` macro.
// See: `BaseException_new`
if cls.name() == vm.ctx.exceptions.os_error.name() {
match os_error_optional_new(args.args.to_vec(), vm) {
Some(error) => error.unwrap().into_pyresult(vm),
None => PyBaseException::slot_new(cls, args, vm),
}
} else {
PyBaseException::slot_new(cls, args, vm)
}
}
#[cfg(target_arch = "wasm32")]
fn os_error_new(cls: PyTypeRef, args: FuncArgs, vm: &VirtualMachine) -> PyResult {
PyBaseException::slot_new(cls, args, vm)
}

fn base_exception_init(
zelf: PyRef<PyBaseException>,
args: FuncArgs,
vm: &VirtualMachine,
) -> PyResult<()> {
PyBaseException::init(zelf, args, vm)
}

define_exception! {
PyBlockingIOError,
PyOSError,
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub mod errors {
}
}

#[cfg(any(unix, windows))]
#[cfg(any(unix, windows, target_os = "wasi"))]
macro_rules! e {
($name:ident) => {
(stringify!($name), errors::$name as _)
Expand All @@ -50,7 +50,7 @@ macro_rules! e {
};
}

#[cfg(any(unix, windows))]
#[cfg(any(unix, windows, target_os = "wasi"))]
const ERROR_CODES: &[(&str, i32)] = &[
e!(ENODEV),
e!(EHOSTUNREACH),
Expand Down Expand Up @@ -218,5 +218,5 @@ const ERROR_CODES: &[(&str, i32)] = &[
e!(cfg(windows), WSAENETRESET),
];

#[cfg(not(any(unix, windows)))]
#[cfg(not(any(unix, windows, target_os = "wasi")))]
const ERROR_CODES: &[(&str, i32)] = &[];
2 changes: 1 addition & 1 deletion vm/src/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod atexit;
pub mod builtins;
mod codecs;
mod collections;
mod errno;
pub mod errno;
mod functools;
mod imp;
pub mod io;
Expand Down