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
Update pystruct + array
  • Loading branch information
coolreader18 committed Oct 26, 2020
commit 0f84bd4070073fcb99d6d02f9aeecb26402db09f
4 changes: 0 additions & 4 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,6 @@ def __bool__(self):
for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']:
self.assertTrue(struct.unpack('>?', c)[0])

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_count_overflow(self):
hugecount = '{}b'.format(sys.maxsize+1)
self.assertRaises(struct.error, struct.calcsize, hugecount)
Expand Down Expand Up @@ -621,8 +619,6 @@ def test_boundary_error_message_with_negative_offset(self):
"offset -11 out of range for 10-byte buffer"):
struct.unpack_from('<B', byte_list, -11)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_boundary_error_message_with_large_offset(self):
# Test overflows cause by large offset and value size (issue 30245)
regex1 = (
Expand Down
35 changes: 16 additions & 19 deletions vm/src/stdlib/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl fmt::Display for ArrayTypeSpecifierError {
}

macro_rules! def_array_enum {
($(($n:ident, $t:ident, $c:literal)),*$(,)?) => {
($(($n:ident, $t:ty, $c:literal)),*$(,)?) => {
#[derive(Debug, Clone)]
pub(crate) enum ArrayContentType {
$($n(Vec<$t>),)*
Expand Down Expand Up @@ -79,7 +79,7 @@ macro_rules! def_array_enum {
fn push(&mut self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
match self {
$(ArrayContentType::$n(v) => {
let val = $t::try_into_from_object(vm, obj)?;
let val = <$t>::try_into_from_object(vm, obj)?;
v.push(val);
})*
}
Expand All @@ -97,7 +97,7 @@ macro_rules! def_array_enum {
fn insert(&mut self, i: usize, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
match self {
$(ArrayContentType::$n(v) => {
let val = $t::try_into_from_object(vm, obj)?;
let val = <$t>::try_into_from_object(vm, obj)?;
v.insert(i, val);
})*
}
Expand All @@ -107,7 +107,7 @@ macro_rules! def_array_enum {
fn count(&self, obj: PyObjectRef, vm: &VirtualMachine) -> usize {
match self {
$(ArrayContentType::$n(v) => {
if let Ok(val) = $t::try_into_from_object(vm, obj) {
if let Ok(val) = <$t>::try_into_from_object(vm, obj) {
v.iter().filter(|&&a| a == val).count()
} else {
0
Expand All @@ -119,7 +119,7 @@ macro_rules! def_array_enum {
fn remove(&mut self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<()>{
match self {
$(ArrayContentType::$n(v) => {
if let Ok(val) = $t::try_into_from_object(vm, obj) {
if let Ok(val) = <$t>::try_into_from_object(vm, obj) {
if let Some(pos) = v.iter().position(|&a| a == val) {
v.remove(pos);
return Ok(());
Expand Down Expand Up @@ -151,7 +151,7 @@ macro_rules! def_array_enum {
.borrow_value()
.iter()
.cloned()
.map(|value| $t::try_into_from_object(vm, value))
.map(|value| <$t>::try_into_from_object(vm, value))
.try_collect()?;
v.append(&mut list);
Ok(())
Expand Down Expand Up @@ -184,7 +184,7 @@ macro_rules! def_array_enum {
fn index(&self, obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
match self {
$(ArrayContentType::$n(v) => {
if let Ok(val) = $t::try_into_from_object(vm, obj) {
if let Ok(val) = <$t>::try_into_from_object(vm, obj) {
if let Some(pos) = v.iter().position(|&a| a == val) {
return Ok(pos);
}
Expand Down Expand Up @@ -267,7 +267,7 @@ macro_rules! def_array_enum {
fn setitem_by_idx(&mut self, i: isize, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
let i = self.idx(i, "array assignment", vm)?;
match self {
$(ArrayContentType::$n(v) => { v[i] = $t::try_into_from_object(vm, value)? },)*
$(ArrayContentType::$n(v) => { v[i] = <$t>::try_into_from_object(vm, value)? },)*
}
Ok(())
}
Expand Down Expand Up @@ -397,17 +397,14 @@ def_array_enum!(
(SignedByte, i8, 'b'),
(UnsignedByte, u8, 'B'),
// TODO: support unicode char
(SignedShort, i16, 'h'),
(UnsignedShort, u16, 'H'),
(SignedInt, i32, 'i'),
(UnsignedInt, u32, 'I'),
(SignedLong, i32, 'l'),
(UnsignedLong, u32, 'L'),
// FIXME: architecture depended size
// (SignedLong, i64, 'l'),
// (UnsignedLong, u64, 'L'),
(SignedLongLong, i64, 'q'),
(UnsignedLongLong, u64, 'Q'),
(SignedShort, libc::c_short, 'h'),
(UnsignedShort, libc::c_ushort, 'H'),
(SignedInt, libc::c_int, 'i'),
(UnsignedInt, libc::c_uint, 'I'),
(SignedLong, libc::c_long, 'l'),
(UnsignedLong, libc::c_ulong, 'L'),
(SignedLongLong, libc::c_longlong, 'q'),
(UnsignedLongLong, libc::c_ulonglong, 'Q'),
(Float, f32, 'f'),
(Double, f64, 'd'),
);
Expand Down
Loading