Skip to content

Commit 4d19f9a

Browse files
authored
Merge pull request #3224 from youknowone/remove-tryformobject-bigint
Remove TryFromBorrowedObject for BigInt
2 parents d2fe6e8 + 70f1cc8 commit 4d19f9a

2 files changed

Lines changed: 33 additions & 38 deletions

File tree

‎vm/src/builtins/int.rs‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ macro_rules! impl_into_pyobject_int {
7878
)*};
7979
}
8080

81-
impl_into_pyobject_int!(isize i8 i16 i32 i64 usize u8 u16 u32 u64 BigInt);
81+
impl_into_pyobject_int!(isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 BigInt);
8282

8383
macro_rules! impl_try_from_object_int {
8484
($(($t:ty, $to_prim:ident),)*) => {$(
@@ -98,19 +98,15 @@ impl_try_from_object_int!(
9898
(i16, to_i16),
9999
(i32, to_i32),
100100
(i64, to_i64),
101+
(i128, to_i128),
101102
(usize, to_usize),
102103
(u8, to_u8),
103104
(u16, to_u16),
104105
(u32, to_u32),
105106
(u64, to_u64),
107+
(u128, to_u128),
106108
);
107109

108-
impl TryFromBorrowedObject for BigInt {
109-
fn try_from_borrowed_object(vm: &VirtualMachine, obj: &PyObjectRef) -> PyResult<Self> {
110-
try_value_from_borrowed_object(vm, obj, |int: &PyInt| Ok(int.as_bigint().clone()))
111-
}
112-
}
113-
114110
fn inner_pow(int1: &BigInt, int2: &BigInt, vm: &VirtualMachine) -> PyResult {
115111
if int2.is_negative() {
116112
let v1 = try_to_float(int1, vm)?;

‎vm/src/stdlib/os.rs‎

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ pub(super) mod _os {
426426
};
427427
use crate::common::lock::{OnceCell, PyRwLock};
428428
use crate::{
429-
builtins::{PyBytesRef, PyStrRef, PyTuple, PyTupleRef, PyTypeRef},
429+
builtins::{PyBytesRef, PyIntRef, PyStrRef, PyTuple, PyTupleRef, PyTypeRef},
430430
crt_fd::{Fd, Offset},
431431
exceptions::IntoPyException,
432432
function::{ArgBytesLike, FuncArgs, OptionalArg},
@@ -435,12 +435,11 @@ pub(super) mod _os {
435435
suppress_iph,
436436
utils::Either,
437437
vm::{ReprGuard, VirtualMachine},
438-
IntoPyObject, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue,
438+
IntoPyObject, IntoPyRef, PyObjectRef, PyRef, PyResult, PyStructSequence, PyValue,
439439
TryFromBorrowedObject, TryFromObject, TypeProtocol,
440440
};
441441
use crossbeam_utils::atomic::AtomicCell;
442442
use itertools::Itertools;
443-
use num_bigint::BigInt;
444443
use std::ffi;
445444
use std::fs::OpenOptions;
446445
use std::io::{self, Read, Write};
@@ -950,37 +949,37 @@ pub(super) mod _os {
950949
#[pyclass(module = "os", name = "stat_result")]
951950
#[derive(Debug, PyStructSequence, FromArgs)]
952951
struct StatResult {
953-
pub st_mode: BigInt,
954-
pub st_ino: BigInt,
955-
pub st_dev: BigInt,
956-
pub st_nlink: BigInt,
957-
pub st_uid: BigInt,
958-
pub st_gid: BigInt,
959-
pub st_size: BigInt,
952+
pub st_mode: PyIntRef,
953+
pub st_ino: PyIntRef,
954+
pub st_dev: PyIntRef,
955+
pub st_nlink: PyIntRef,
956+
pub st_uid: PyIntRef,
957+
pub st_gid: PyIntRef,
958+
pub st_size: PyIntRef,
960959
// TODO: unnamed structsequence fields
961960
#[pyarg(positional, default)]
962-
pub __st_atime_int: BigInt,
961+
pub __st_atime_int: libc::time_t,
963962
#[pyarg(positional, default)]
964-
pub __st_mtime_int: BigInt,
963+
pub __st_mtime_int: libc::time_t,
965964
#[pyarg(positional, default)]
966-
pub __st_ctime_int: BigInt,
965+
pub __st_ctime_int: libc::time_t,
967966
#[pyarg(any, default)]
968967
pub st_atime: f64,
969968
#[pyarg(any, default)]
970969
pub st_mtime: f64,
971970
#[pyarg(any, default)]
972971
pub st_ctime: f64,
973972
#[pyarg(any, default)]
974-
pub st_atime_ns: BigInt,
973+
pub st_atime_ns: i128,
975974
#[pyarg(any, default)]
976-
pub st_mtime_ns: BigInt,
975+
pub st_mtime_ns: i128,
977976
#[pyarg(any, default)]
978-
pub st_ctime_ns: BigInt,
977+
pub st_ctime_ns: i128,
979978
}
980979

981980
#[pyimpl(with(PyStructSequence))]
982981
impl StatResult {
983-
fn from_stat(stat: &StatStruct) -> Self {
982+
fn from_stat(stat: &StatStruct, vm: &VirtualMachine) -> Self {
984983
let (atime, mtime, ctime);
985984
#[cfg(any(unix, windows))]
986985
{
@@ -999,22 +998,22 @@ pub(super) mod _os {
999998
let to_f64 = |(s, ns)| (s as f64) + (ns as f64) / (NANOS_PER_SEC as f64);
1000999
let to_ns = |(s, ns)| s as i128 * NANOS_PER_SEC as i128 + ns as i128;
10011000
StatResult {
1002-
st_mode: stat.st_mode.into(),
1003-
st_ino: stat.st_ino.into(),
1004-
st_dev: stat.st_dev.into(),
1005-
st_nlink: stat.st_nlink.into(),
1006-
st_uid: stat.st_uid.into(),
1007-
st_gid: stat.st_gid.into(),
1008-
st_size: stat.st_size.into(),
1009-
__st_atime_int: atime.0.into(),
1010-
__st_mtime_int: mtime.0.into(),
1011-
__st_ctime_int: ctime.0.into(),
1001+
st_mode: stat.st_mode.into_pyref(vm),
1002+
st_ino: stat.st_ino.into_pyref(vm),
1003+
st_dev: stat.st_dev.into_pyref(vm),
1004+
st_nlink: stat.st_nlink.into_pyref(vm),
1005+
st_uid: stat.st_uid.into_pyref(vm),
1006+
st_gid: stat.st_gid.into_pyref(vm),
1007+
st_size: stat.st_size.into_pyref(vm),
1008+
__st_atime_int: atime.0,
1009+
__st_mtime_int: mtime.0,
1010+
__st_ctime_int: ctime.0,
10121011
st_atime: to_f64(atime),
10131012
st_mtime: to_f64(mtime),
10141013
st_ctime: to_f64(ctime),
1015-
st_atime_ns: to_ns(atime).into(),
1016-
st_mtime_ns: to_ns(mtime).into(),
1017-
st_ctime_ns: to_ns(ctime).into(),
1014+
st_atime_ns: to_ns(atime),
1015+
st_mtime_ns: to_ns(mtime),
1016+
st_ctime_ns: to_ns(ctime),
10181017
}
10191018
}
10201019

@@ -1178,7 +1177,7 @@ pub(super) mod _os {
11781177
let stat = stat_inner(file.clone(), dir_fd, follow_symlinks)
11791178
.map_err(|e| IOErrorBuilder::new(e).filename(file).into_pyexception(vm))?
11801179
.ok_or_else(|| crate::exceptions::cstring_error(vm))?;
1181-
Ok(StatResult::from_stat(&stat).into_pyobject(vm))
1180+
Ok(StatResult::from_stat(&stat, vm).into_pyobject(vm))
11821181
}
11831182

11841183
#[pyfunction]

0 commit comments

Comments
 (0)