Skip to content

Commit 8a085b8

Browse files
committed
Drop PyArray::as_cell_slice due to its unsound interactions with PyReadonlyArray.
1 parent e7b851b commit 8a085b8

File tree

2 files changed

+2
-15
lines changed

2 files changed

+2
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Support borrowing arrays that are part of other Python objects via `PyArray::borrow_from_array` ([#230](https://github.com/PyO3/rust-numpy/pull/216))
66
- `PyArray::new` is now `unsafe`, as it produces uninitialized arrays ([#220](https://github.com/PyO3/rust-numpy/pull/220))
77
- `PyArray::from_exact_iter` does not unsoundly trust `ExactSizeIterator::len` any more ([#262](https://github.com/PyO3/rust-numpy/pull/262))
8+
- `PyArray::as_cell_slice` was removed as it unsoundly interacts with `PyReadonlyArray` allowing safe code to violate aliasing rules ([#260](https://github.com/PyO3/rust-numpy/pull/260))
89
- `rayon` feature is now removed, and directly specifying the feature via `ndarray` dependency is recommended ([#250](https://github.com/PyO3/rust-numpy/pull/250))
910
- Descriptors rework and related changes ([#256](https://github.com/PyO3/rust-numpy/pull/256)):
1011
- Remove `DataType`

src/array.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Safe interface for NumPy ndarray
22
use std::{
3-
cell::Cell,
43
marker::PhantomData,
54
mem,
65
os::raw::{c_int, c_void},
@@ -603,9 +602,7 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
603602

604603
/// Returns the immutable view of the internal data of `PyArray` as slice.
605604
///
606-
/// Please consider the use of safe alternatives
607-
/// ([`PyReadonlyArray::as_slice`](../struct.PyReadonlyArray.html#method.as_slice)
608-
/// , [`as_cell_slice`](#method.as_cell_slice) or [`to_vec`](#method.to_vec)) instead of this.
605+
/// Please consider the use of the safe alternative [`PyReadonlyArray::as_slice`].
609606
///
610607
/// # Safety
611608
/// If the internal array is not readonly and can be mutated from Python code,
@@ -618,22 +615,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
618615
}
619616
}
620617

621-
/// Returns the view of the internal data of `PyArray` as `&[Cell<T>]`.
622-
pub fn as_cell_slice(&self) -> Result<&[Cell<T>], NotContiguousError> {
623-
if !self.is_contiguous() {
624-
Err(NotContiguousError)
625-
} else {
626-
Ok(unsafe { slice::from_raw_parts(self.data() as _, self.len()) })
627-
}
628-
}
629-
630618
/// Returns the view of the internal data of `PyArray` as mutable slice.
631619
///
632620
/// # Safety
633621
/// If another reference to the internal data exists(e.g., `&[T]` or `ArrayView`),
634622
/// it might cause undefined behavior.
635-
///
636-
/// In such case, please consider the use of [`as_cell_slice`](#method.as_cell_slice),
637623
pub unsafe fn as_slice_mut(&self) -> Result<&mut [T], NotContiguousError> {
638624
if !self.is_contiguous() {
639625
Err(NotContiguousError)

0 commit comments

Comments
 (0)