PyO3 / rust-numpy

PyO3-based Rust bindings of the NumPy C-API
BSD 2-Clause "Simplified" License
1.11k stars 106 forks source link

Make the internal PyArray::data function safe #304

Closed adamreichold closed 2 years ago

adamreichold commented 2 years ago

Noticed this while working on #299: While doing anything with the resulting pointer requires unsafe, producing the pointer should not. (Dereferencing self.as_array_ptr() should be safe for the same reasons that dereferencing it in say PyArray::shape is, i.e. we ensure that PyArray<T,D> is only constructed for NumPy arrays.)