Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion Lib/test/test_lzma.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,6 @@ def test_init_bad_check(self):
with self.assertRaises(ValueError):
LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_UNKNOWN)

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u32
def test_init_bad_preset(self):
with self.assertRaises(TypeError):
LZMAFile(BytesIO(), "w", preset=4.39)
Expand Down
8 changes: 0 additions & 8 deletions Lib/test/test_memoryio.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,10 +934,6 @@ def test_flags(self):
def test_write(self):
return super().test_write()

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u64
def test_seek(self):
return super().test_seek()

class CStringIOTest(PyStringIOTest):
ioclass = io.StringIO
UnsupportedOperation = io.UnsupportedOperation
Expand Down Expand Up @@ -1030,10 +1026,6 @@ def test_flags(self):
def test_newlines_property(self):
return super().test_newlines_property()

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u64
def test_seek(self):
return super().test_seek()

@unittest.expectedFailure # TODO: RUSTPYTHON; d
def test_newline_cr(self):
return super().test_newline_cr()
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def expected(cur):
resource.setrlimit(resource.RLIMIT_FSIZE, (2**64-5, max))
self.assertIn(resource.getrlimit(resource.RLIMIT_FSIZE), expected(2**64-5))

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u64
@unittest.skipIf(sys.platform == "vxworks",
"setting RLIMIT_FSIZE is not supported on VxWorks")
@unittest.skipUnless(hasattr(resource, 'RLIMIT_FSIZE'), 'requires resource.RLIMIT_FSIZE')
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,6 @@ def testInterfaceNameIndex(self):
self.assertIsInstance(_name, str)
self.assertEqual(name, _name)

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u32
@unittest.skipUnless(hasattr(socket, 'if_indextoname'),
'socket.if_indextoname() not available.')
@support.skip_android_selinux('if_indextoname')
Expand Down Expand Up @@ -1249,7 +1248,6 @@ def testNtoH(self):
self.assertEqual(swapped & mask, mask)
self.assertRaises(OverflowError, func, 1<<34)

@unittest.expectedFailure # TODO: RUSTPYTHON; OverflowError: Python int too large to convert to Rust u16
def testNtoHErrors(self):
s_good_values = [0, 1, 2, 0xffff]
l_good_values = s_good_values + [0xffffffff]
Expand Down
2 changes: 1 addition & 1 deletion crates/stdlib/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ pub mod array {
($($t:ty,)*) => {$(
impl ArrayElement for $t {
fn try_into_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
obj.try_index(vm)?.try_to_primitive(vm)
obj.try_index(vm)?.try_to_primitive_raw(vm)
}
fn byteswap(self) -> Self {
<$t>::swap_bytes(self)
Expand Down
8 changes: 5 additions & 3 deletions crates/stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2230,7 +2230,7 @@ mod _socket {
let addr = Self::from_tuple(tuple, vm)?;
let flowinfo = tuple
.get(2)
.map(|obj| u32::try_from_borrowed_object(vm, obj))
.map(|obj| obj.clone().try_index(vm)?.try_to_primitive_raw(vm))
.transpose()?
.unwrap_or(0);
let scopeid = tuple
Expand Down Expand Up @@ -3141,14 +3141,16 @@ mod _socket {

#[cfg(all(unix, not(target_os = "redox")))]
#[pyfunction(name = "CMSG_LEN")]
fn cmsg_len(length: usize, vm: &VirtualMachine) -> PyResult<usize> {
fn cmsg_len(length: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
let length = length.try_index(vm)?.try_to_primitive_raw(vm)?;
host_socket::checked_cmsg_len(length)
.ok_or_else(|| vm.new_overflow_error("CMSG_LEN() argument out of range"))
}

#[cfg(all(unix, not(target_os = "redox")))]
#[pyfunction(name = "CMSG_SPACE")]
fn cmsg_space(length: usize, vm: &VirtualMachine) -> PyResult<usize> {
fn cmsg_space(length: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
let length = length.try_index(vm)?.try_to_primitive_raw(vm)?;
host_socket::checked_cmsg_space(length)
.ok_or_else(|| vm.new_overflow_error("CMSG_SPACE() argument out of range"))
}
Expand Down
16 changes: 10 additions & 6 deletions crates/vm/src/builtins/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,17 @@ impl PyInt {
where
I: PrimInt + TryFrom<&'a BigInt>,
{
// TODO: Python 3.14+: ValueError for negative int to unsigned type
// See stdlib_socket.py socket.htonl(-1)
//
// if I::min_value() == I::zero() && self.as_bigint().sign() == Sign::Minus {
// return Err(vm.new_value_error("Cannot convert negative int".to_owned()));
// }
if I::min_value() == I::zero() && self.as_bigint().sign() == Sign::Minus {
return Err(vm.new_value_error("can't convert negative number to unsigned"));
}

self.try_to_primitive_raw(vm)
}

pub fn try_to_primitive_raw<'a, I>(&'a self, vm: &VirtualMachine) -> PyResult<I>
where
I: PrimInt + TryFrom<&'a BigInt>,
{
I::try_from(self.as_bigint()).map_err(|_| {
vm.new_overflow_error(format!(
"Python int too large to convert to Rust {}",
Expand Down
3 changes: 2 additions & 1 deletion crates/vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,8 @@ pub(super) mod _os {

#[cfg(windows)]
#[pyfunction]
fn waitstatus_to_exitcode(status: u64, vm: &VirtualMachine) -> PyResult<u32> {
fn waitstatus_to_exitcode(status: PyObjectRef, vm: &VirtualMachine) -> PyResult<u32> {
let status = status.try_index(vm)?.try_to_primitive_raw::<u64>(vm)?;
let exitcode = status >> 8;
// ExitProcess() accepts an UINT type:
// reject exit code which doesn't fit in an UINT
Expand Down
Loading