Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Fix wasm32 build
  • Loading branch information
youknowone committed Apr 18, 2022
commit f8f4392cf397f062a79153869a85614d0e01baa8
9 changes: 7 additions & 2 deletions vm/src/exceptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,17 +1023,22 @@ pub(crate) fn raw_os_error_to_exc_type(errno: i32, vm: &VirtualMachine) -> Optio
}
}

#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
pub(crate) fn raw_os_error_to_exc_type(_errno: i32, _vm: &VirtualMachine) -> Option<PyTypeRef> {
None
}

pub(super) mod types {
use crate::common::lock::PyRwLock;
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
#[cfg_attr(target_arch = "wasm32", allow(unused_imports))]
use crate::{
builtins::{traceback::PyTracebackRef, PyInt, PyTupleRef, PyTypeRef},
convert::ToPyResult,
function::FuncArgs,
PyObjectRef, PyRef, PyResult, VirtualMachine,
};
use crossbeam_utils::atomic::AtomicCell;
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
#[cfg_attr(target_arch = "wasm32", allow(unused_imports))]
use std::ops::Deref;

// This module is designed to be used as `use builtins::*;`.
Expand Down
30 changes: 28 additions & 2 deletions vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,34 @@ cfg_if::cfg_if! {
}
}

use crate::{PyObjectRef, PyResult, TryFromObject, VirtualMachine};
pub(crate) use _io::io_open as open;
use crate::{
builtins::PyBaseExceptionRef,
convert::{ToPyException, ToPyObject},
PyObjectRef, PyResult, TryFromObject, VirtualMachine,
};
pub use _io::io_open as open;

impl ToPyException for &'_ std::io::Error {
fn to_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
use std::io::ErrorKind;

let excs = &vm.ctx.exceptions;
#[allow(unreachable_patterns)] // some errors are just aliases of each other
let exc_type = match self.kind() {
ErrorKind::NotFound => excs.file_not_found_error.clone(),
ErrorKind::PermissionDenied => excs.permission_error.clone(),
ErrorKind::AlreadyExists => excs.file_exists_error.clone(),
ErrorKind::WouldBlock => excs.blocking_io_error.clone(),
_ => self
.raw_os_error()
.and_then(|errno| crate::exceptions::raw_os_error_to_exc_type(errno, vm))
.unwrap_or_else(|| excs.os_error.clone()),
};
let errno = self.raw_os_error().to_pyobject(vm);
let msg = vm.ctx.new_str(self.to_string()).into();
vm.new_exception(exc_type, vec![errno, msg])
}
}

pub(crate) fn make_module(vm: &VirtualMachine) -> PyObjectRef {
let ctx = &vm.ctx;
Expand Down
28 changes: 1 addition & 27 deletions vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::{
VirtualMachine,
};
use std::{
ffi, fs,
io::{self, ErrorKind},
ffi, fs, io,
path::{Path, PathBuf},
};

Expand Down Expand Up @@ -236,31 +235,6 @@ impl PathOrFd {
}
}

impl ToPyException for io::Error {
fn to_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
(&self).to_pyexception(vm)
}
}
impl ToPyException for &'_ io::Error {
fn to_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
let excs = &vm.ctx.exceptions;
#[allow(unreachable_patterns)] // some errors are just aliases of each other
let exc_type = match self.kind() {
ErrorKind::NotFound => excs.file_not_found_error.clone(),
ErrorKind::PermissionDenied => excs.permission_error.clone(),
ErrorKind::AlreadyExists => excs.file_exists_error.clone(),
ErrorKind::WouldBlock => excs.blocking_io_error.clone(),
_ => self
.raw_os_error()
.and_then(|errno| crate::exceptions::raw_os_error_to_exc_type(errno, vm))
.unwrap_or_else(|| excs.os_error.clone()),
};
let errno = self.raw_os_error().to_pyobject(vm);
let msg = vm.ctx.new_str(self.to_string()).into();
vm.new_exception(exc_type, vec![errno, msg])
}
}

#[cfg(unix)]
impl ToPyException for nix::Error {
fn to_pyexception(self, vm: &VirtualMachine) -> PyBaseExceptionRef {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/thread.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Implementation of the _thread module
#[cfg_attr(target_os = "wasi", allow(unused_imports))]
#[cfg_attr(target_arch = "wasm32", allow(unused_imports))]
pub(crate) use _thread::{make_module, RawRMutex};

#[pymodule]
Expand Down