Skip to content

Commit

Permalink
PySlice: fix isize->long truncation in initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Nov 22, 2022
1 parent 8ca41be commit fb6cba9
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/types/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ impl PySlice {
pub fn new(py: Python<'_>, start: isize, stop: isize, step: isize) -> &PySlice {
unsafe {
let ptr = ffi::PySlice_New(
ffi::PyLong_FromLong(start as c_long),
ffi::PyLong_FromLong(stop as c_long),
ffi::PyLong_FromLong(step as c_long),
ffi::PyLong_FromSsize_t(start),
ffi::PyLong_FromSsize_t(stop),
ffi::PyLong_FromSsize_t(step),
);
py.from_owned_ptr(ptr)
}
Expand Down Expand Up @@ -99,6 +99,25 @@ impl ToPyObject for PySliceIndices {
mod tests {
use super::*;

#[test]
fn test_py_slice_new() {
Python::with_gil(|py| {
let slice = PySlice::new(py, isize::MIN, isize::MAX, 1);
assert_eq!(
slice.getattr("start").unwrap().extract::<isize>().unwrap(),
isize::MIN
);
assert_eq!(
slice.getattr("stop").unwrap().extract::<isize>().unwrap(),
isize::MAX
);
assert_eq!(
slice.getattr("step").unwrap().extract::<isize>().unwrap(),
1
);
});
}

#[test]
fn test_py_slice_indices_new() {
let start = 0;
Expand Down

0 comments on commit fb6cba9

Please sign in to comment.