Skip to content
Open
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_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,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
16 changes: 8 additions & 8 deletions crates/stdlib/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,23 +845,23 @@ mod _socket {
}

#[pyfunction]
const fn htonl(x: u32) -> u32 {
u32::to_be(x)
fn htonl(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<u32> {
Ok(u32::to_be(x.try_index(vm)?.try_to_primitive::<u32>(vm)?))
}

#[pyfunction]
const fn htons(x: u16) -> u16 {
u16::to_be(x)
fn htons(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<u16> {
Ok(u16::to_be(x.try_index(vm)?.try_to_primitive::<u16>(vm)?))
}

#[pyfunction]
const fn ntohl(x: u32) -> u32 {
u32::from_be(x)
fn ntohl(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<u32> {
Ok(u32::from_be(x.try_index(vm)?.try_to_primitive::<u32>(vm)?))
}

#[pyfunction]
const fn ntohs(x: u16) -> u16 {
u16::from_be(x)
fn ntohs(x: PyObjectRef, vm: &VirtualMachine) -> PyResult<u16> {
Ok(u16::from_be(x.try_index(vm)?.try_to_primitive::<u16>(vm)?))
}

#[cfg(unix)]
Expand Down
9 changes: 3 additions & 6 deletions crates/vm/src/builtins/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,9 @@ 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"));
}

I::try_from(self.as_bigint()).map_err(|_| {
vm.new_overflow_error(format!(
Expand Down
Loading