Skip to content

Commit 8f17468

Browse files
Karatussyouknowone
authored andcommitted
Fix mul/repeat index type to isize
1 parent ef873b4 commit 8f17468

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

vm/src/builtins/bytearray.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl AsSequence for PyByteArray {
820820
}),
821821
repeat: atomic_func!(|seq, n, vm| {
822822
PyByteArray::sequence_downcast(seq)
823-
.mul(n as isize, vm)
823+
.mul(n, vm)
824824
.map(|x| x.into_pyobject(vm))
825825
}),
826826
item: atomic_func!(|seq, i, vm| {
@@ -849,7 +849,7 @@ impl AsSequence for PyByteArray {
849849
}),
850850
inplace_repeat: atomic_func!(|seq, n, vm| {
851851
let zelf = PyByteArray::sequence_downcast(seq).to_owned();
852-
PyByteArray::imul(zelf, n as isize, vm).map(|x| x.into())
852+
PyByteArray::imul(zelf, n, vm).map(|x| x.into())
853853
}),
854854
};
855855
&AS_SEQUENCE

vm/src/builtins/bytes.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,10 +604,11 @@ impl AsSequence for PyBytes {
604604
.map(|x| vm.ctx.new_bytes(x).into())
605605
}),
606606
repeat: atomic_func!(|seq, n, vm| {
607-
Ok(vm
608-
.ctx
609-
.new_bytes(PyBytes::sequence_downcast(seq).repeat(n))
610-
.into())
607+
if let Ok(zelf) = seq.obj.to_owned().downcast::<PyBytes>() {
608+
PyBytes::mul(zelf, n, vm).to_pyresult(vm)
609+
} else {
610+
Err(vm.new_type_error("bad argument type for built-in operation".to_owned()))
611+
}
611612
}),
612613
item: atomic_func!(|seq, i, vm| {
613614
PyBytes::sequence_downcast(seq)

vm/src/builtins/list.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,7 @@ impl AsSequence for PyList {
431431
.map(|x| x.into())
432432
}),
433433
repeat: atomic_func!(|seq, n, vm| {
434-
PyList::sequence_downcast(seq)
435-
.mul(n as isize, vm)
436-
.map(|x| x.into())
434+
PyList::sequence_downcast(seq).mul(n, vm).map(|x| x.into())
437435
}),
438436
item: atomic_func!(|seq, i, vm| {
439437
PyList::sequence_downcast(seq)
@@ -458,7 +456,7 @@ impl AsSequence for PyList {
458456
}),
459457
inplace_repeat: atomic_func!(|seq, n, vm| {
460458
let zelf = PyList::sequence_downcast(seq);
461-
zelf.borrow_vec_mut().imul(vm, n as isize)?;
459+
zelf.borrow_vec_mut().imul(vm, n)?;
462460
Ok(zelf.to_owned().into())
463461
}),
464462
};

vm/src/builtins/str.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ impl AsSequence for PyStr {
12911291
}),
12921292
repeat: atomic_func!(|seq, n, vm| {
12931293
let zelf = PyStr::sequence_downcast(seq);
1294-
PyStr::mul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
1294+
PyStr::mul(zelf.to_owned(), n, vm).map(|x| x.into())
12951295
}),
12961296
item: atomic_func!(|seq, i, vm| {
12971297
let zelf = PyStr::sequence_downcast(seq);

vm/src/builtins/tuple.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl AsSequence for PyTuple {
353353
}),
354354
repeat: atomic_func!(|seq, n, vm| {
355355
let zelf = PyTuple::sequence_downcast(seq);
356-
PyTuple::mul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
356+
PyTuple::mul(zelf.to_owned(), n, vm).map(|x| x.into())
357357
}),
358358
item: atomic_func!(|seq, i, vm| {
359359
let zelf = PyTuple::sequence_downcast(seq);

vm/src/protocol/sequence.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ impl PyObject {
2929
pub struct PySequenceMethods {
3030
pub length: AtomicCell<Option<fn(PySequence, &VirtualMachine) -> PyResult<usize>>>,
3131
pub concat: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult>>,
32-
pub repeat: AtomicCell<Option<fn(PySequence, usize, &VirtualMachine) -> PyResult>>,
32+
pub repeat: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
3333
pub item: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
3434
pub ass_item: AtomicCell<
3535
Option<fn(PySequence, isize, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>>,
3636
>,
3737
pub contains: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult<bool>>>,
3838
pub inplace_concat: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult>>,
39-
pub inplace_repeat: AtomicCell<Option<fn(PySequence, usize, &VirtualMachine) -> PyResult>>,
39+
pub inplace_repeat: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
4040
}
4141

4242
impl Debug for PySequenceMethods {
@@ -130,7 +130,7 @@ impl PySequence<'_> {
130130
)))
131131
}
132132

133-
pub fn repeat(self, n: usize, vm: &VirtualMachine) -> PyResult {
133+
pub fn repeat(self, n: isize, vm: &VirtualMachine) -> PyResult {
134134
if let Some(f) = self.methods.repeat.load() {
135135
return f(self, n, vm);
136136
}
@@ -168,7 +168,7 @@ impl PySequence<'_> {
168168
)))
169169
}
170170

171-
pub fn inplace_repeat(self, n: usize, vm: &VirtualMachine) -> PyResult {
171+
pub fn inplace_repeat(self, n: isize, vm: &VirtualMachine) -> PyResult {
172172
if let Some(f) = self.methods.inplace_repeat.load() {
173173
return f(self, n, vm);
174174
}

vm/src/stdlib/collections.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ mod _collections {
525525
}),
526526
repeat: atomic_func!(|seq, n, vm| {
527527
PyDeque::sequence_downcast(seq)
528-
.mul(n as isize, vm)
528+
.mul(n, vm)
529529
.map(|x| x.into_ref(vm).into())
530530
}),
531531
item: atomic_func!(|seq, i, vm| PyDeque::sequence_downcast(seq).getitem(i, vm)),
@@ -547,7 +547,7 @@ mod _collections {
547547
}),
548548
inplace_repeat: atomic_func!(|seq, n, vm| {
549549
let zelf = PyDeque::sequence_downcast(seq);
550-
PyDeque::imul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
550+
PyDeque::imul(zelf.to_owned(), n, vm).map(|x| x.into())
551551
}),
552552
};
553553

0 commit comments

Comments
 (0)