mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Fix mul/repeat index type to isize
This commit is contained in:
1 parent
ef873b4b60
commit
8f17468f51
7 files changed
+17
-18
No files matched your search
@@ -820,7 +820,7 @@ impl AsSequence for PyByteArray {
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
PyByteArray::sequence_downcast(seq)
|
||||
.mul(n as isize, vm)
|
||||
.mul(n, vm)
|
||||
.map(|x| x.into_pyobject(vm))
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
@@ -849,7 +849,7 @@ impl AsSequence for PyByteArray {
|
||||
}),
|
||||
inplace_repeat: atomic_func!(|seq, n, vm| {
|
||||
let zelf = PyByteArray::sequence_downcast(seq).to_owned();
|
||||
PyByteArray::imul(zelf, n as isize, vm).map(|x| x.into())
|
||||
PyByteArray::imul(zelf, n, vm).map(|x| x.into())
|
||||
}),
|
||||
};
|
||||
&AS_SEQUENCE
|
||||
|
||||
@@ -604,10 +604,11 @@ impl AsSequence for PyBytes {
|
||||
.map(|x| vm.ctx.new_bytes(x).into())
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
Ok(vm
|
||||
.ctx
|
||||
.new_bytes(PyBytes::sequence_downcast(seq).repeat(n))
|
||||
.into())
|
||||
if let Ok(zelf) = seq.obj.to_owned().downcast::<PyBytes>() {
|
||||
PyBytes::mul(zelf, n, vm).to_pyresult(vm)
|
||||
} else {
|
||||
Err(vm.new_type_error("bad argument type for built-in operation".to_owned()))
|
||||
}
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
PyBytes::sequence_downcast(seq)
|
||||
|
||||
@@ -431,9 +431,7 @@ impl AsSequence for PyList {
|
||||
.map(|x| x.into())
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
PyList::sequence_downcast(seq)
|
||||
.mul(n as isize, vm)
|
||||
.map(|x| x.into())
|
||||
PyList::sequence_downcast(seq).mul(n, vm).map(|x| x.into())
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
PyList::sequence_downcast(seq)
|
||||
@@ -458,7 +456,7 @@ impl AsSequence for PyList {
|
||||
}),
|
||||
inplace_repeat: atomic_func!(|seq, n, vm| {
|
||||
let zelf = PyList::sequence_downcast(seq);
|
||||
zelf.borrow_vec_mut().imul(vm, n as isize)?;
|
||||
zelf.borrow_vec_mut().imul(vm, n)?;
|
||||
Ok(zelf.to_owned().into())
|
||||
}),
|
||||
};
|
||||
|
||||
@@ -1291,7 +1291,7 @@ impl AsSequence for PyStr {
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
let zelf = PyStr::sequence_downcast(seq);
|
||||
PyStr::mul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
|
||||
PyStr::mul(zelf.to_owned(), n, vm).map(|x| x.into())
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
let zelf = PyStr::sequence_downcast(seq);
|
||||
|
||||
@@ -353,7 +353,7 @@ impl AsSequence for PyTuple {
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
let zelf = PyTuple::sequence_downcast(seq);
|
||||
PyTuple::mul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
|
||||
PyTuple::mul(zelf.to_owned(), n, vm).map(|x| x.into())
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| {
|
||||
let zelf = PyTuple::sequence_downcast(seq);
|
||||
|
||||
@@ -29,14 +29,14 @@ impl PyObject {
|
||||
pub struct PySequenceMethods {
|
||||
pub length: AtomicCell<Option<fn(PySequence, &VirtualMachine) -> PyResult<usize>>>,
|
||||
pub concat: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult>>,
|
||||
pub repeat: AtomicCell<Option<fn(PySequence, usize, &VirtualMachine) -> PyResult>>,
|
||||
pub repeat: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
|
||||
pub item: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
|
||||
pub ass_item: AtomicCell<
|
||||
Option<fn(PySequence, isize, Option<PyObjectRef>, &VirtualMachine) -> PyResult<()>>,
|
||||
>,
|
||||
pub contains: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult<bool>>>,
|
||||
pub inplace_concat: AtomicCell<Option<fn(PySequence, &PyObject, &VirtualMachine) -> PyResult>>,
|
||||
pub inplace_repeat: AtomicCell<Option<fn(PySequence, usize, &VirtualMachine) -> PyResult>>,
|
||||
pub inplace_repeat: AtomicCell<Option<fn(PySequence, isize, &VirtualMachine) -> PyResult>>,
|
||||
}
|
||||
|
||||
impl Debug for PySequenceMethods {
|
||||
@@ -130,7 +130,7 @@ impl PySequence<'_> {
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn repeat(self, n: usize, vm: &VirtualMachine) -> PyResult {
|
||||
pub fn repeat(self, n: isize, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(f) = self.methods.repeat.load() {
|
||||
return f(self, n, vm);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ impl PySequence<'_> {
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn inplace_repeat(self, n: usize, vm: &VirtualMachine) -> PyResult {
|
||||
pub fn inplace_repeat(self, n: isize, vm: &VirtualMachine) -> PyResult {
|
||||
if let Some(f) = self.methods.inplace_repeat.load() {
|
||||
return f(self, n, vm);
|
||||
}
|
||||
|
||||
@@ -525,7 +525,7 @@ mod _collections {
|
||||
}),
|
||||
repeat: atomic_func!(|seq, n, vm| {
|
||||
PyDeque::sequence_downcast(seq)
|
||||
.mul(n as isize, vm)
|
||||
.mul(n, vm)
|
||||
.map(|x| x.into_ref(vm).into())
|
||||
}),
|
||||
item: atomic_func!(|seq, i, vm| PyDeque::sequence_downcast(seq).getitem(i, vm)),
|
||||
@@ -547,7 +547,7 @@ mod _collections {
|
||||
}),
|
||||
inplace_repeat: atomic_func!(|seq, n, vm| {
|
||||
let zelf = PyDeque::sequence_downcast(seq);
|
||||
PyDeque::imul(zelf.to_owned(), n as isize, vm).map(|x| x.into())
|
||||
PyDeque::imul(zelf.to_owned(), n, vm).map(|x| x.into())
|
||||
}),
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user