Fix compilation on wasi

This commit is contained in:
Noah
2021-07-14 12:12:25 -05:00
committed by Noa
parent aff0e3c2da
commit 2969fa5625

View File

@@ -1533,7 +1533,7 @@ mod _os {
#[pyimpl(with(PyStructSequence))]
impl TimesResult {}
#[cfg(not(target_os = "redox"))]
#[cfg(any(unix, windows))]
#[pyfunction]
fn times(vm: &VirtualMachine) -> PyResult {
#[cfg(windows)]
@@ -1710,17 +1710,22 @@ mod _os {
#[pyimpl(with(PyStructSequence))]
impl UnameResult {}
enum NameOrVal {
Name(String),
Val(i32),
}
#[cfg(unix)]
struct ConfName(i32);
impl TryFromObject for NameOrVal {
#[cfg(unix)]
impl TryFromObject for ConfName {
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
match obj.downcast::<int::PyInt>() {
Ok(int) => int::try_to_primitive(int.as_bigint(), vm).map(Self::Val),
Err(obj) => PyStrRef::try_from_object(vm, obj).map(|o| Self::Name(o.to_string())),
}
let i = match obj.downcast::<int::PyInt>() {
Ok(int) => int::try_to_primitive(int.as_bigint(), vm)?,
Err(obj) => {
let s = PyStrRef::try_from_object(vm, obj)?;
s.as_str().parse::<PathconfVar>().map_err(|_| {
vm.new_value_error("unrecognized configuration name".to_string())
})? as i32
}
};
Ok(Self(i))
}
}
@@ -1894,15 +1899,12 @@ mod _os {
#[cfg(unix)]
#[pyfunction]
fn pathconf(path: PathOrFd, name: NameOrVal, vm: &VirtualMachine) -> PyResult<Option<i64>> {
fn pathconf(
path: PathOrFd,
ConfName(name): ConfName,
vm: &VirtualMachine,
) -> PyResult<Option<i64>> {
use nix::errno::{self, Errno};
use std::str::FromStr;
let name = match name {
NameOrVal::Name(s) => PathconfVar::from_str(&s)
.map_err(|_| vm.new_value_error("unrecognized configuration name".to_string()))?
as i32,
NameOrVal::Val(v) => v,
};
Errno::clear();
let raw = match path {
@@ -1927,7 +1929,7 @@ mod _os {
#[cfg(unix)]
#[pyfunction]
fn fpathconf(fd: i32, name: NameOrVal, vm: &VirtualMachine) -> PyResult<Option<i64>> {
fn fpathconf(fd: i32, name: ConfName, vm: &VirtualMachine) -> PyResult<Option<i64>> {
pathconf(PathOrFd::Fd(fd), name, vm)
}