Skip to content

Commit 28183f1

Browse files
committed
Limit the scope of allowing clippy::missing_safety_doc to the FFI module.
1 parent 669a228 commit 28183f1

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

src/array.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,24 @@ impl<T, D> PyArray<T, D> {
244244
unsafe { Py::from_borrowed_ptr(self.py(), self.as_ptr()) }
245245
}
246246

247-
/// Constructs `PyArray` from raw python object without incrementing reference counts.
247+
/// Constructs `PyArray` from raw Python object without incrementing reference counts.
248+
///
249+
/// # Safety
250+
///
251+
/// Implementations must ensure the object does not get freed during `'py`
252+
/// and ensure that `ptr` is of the correct type.
248253
pub unsafe fn from_owned_ptr(py: Python<'_>, ptr: *mut ffi::PyObject) -> &Self {
249254
py.from_owned_ptr(ptr)
250255
}
251256

252-
/// Constructs PyArray from raw python object and increments reference counts.
253-
pub unsafe fn from_borrowed_ptr(py: Python<'_>, ptr: *mut ffi::PyObject) -> &Self {
257+
/// Constructs PyArray from raw Python object and increments reference counts.
258+
///
259+
/// # Safety
260+
///
261+
/// Implementations must ensure the object does not get freed during `'py`
262+
/// and ensure that `ptr` is of the correct type.
263+
/// Note that it must be safe to decrement the reference count of ptr.
264+
pub unsafe fn from_borrowed_ptr<'py>(py: Python<'py>, ptr: *mut ffi::PyObject) -> &'py Self {
254265
py.from_borrowed_ptr(ptr)
255266
}
256267

@@ -673,7 +684,10 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
673684
///
674685
/// See [NpyIndex](../convert/trait.NpyIndex.html) for what types you can use as index.
675686
///
676-
/// Passing an invalid index can cause undefined behavior(mostly SIGSEGV).
687+
/// # Safety
688+
///
689+
/// Passing an invalid index is undefined behavior. The element must also have been initialized.
690+
/// The elemet must also not be modified by Python code.
677691
///
678692
/// # Example
679693
/// ```
@@ -693,6 +707,11 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
693707
}
694708

695709
/// Same as [uget](#method.uget), but returns `&mut T`.
710+
///
711+
/// # Safety
712+
///
713+
/// Passing an invalid index is undefined behavior. The element must also have been initialized.
714+
/// The element must also not be accessed by Python code.
696715
#[inline(always)]
697716
#[allow(clippy::mut_from_ref)]
698717
pub unsafe fn uget_mut<Idx>(&self, index: Idx) -> &mut T
@@ -704,6 +723,9 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
704723
}
705724

706725
/// Same as [uget](#method.uget), but returns `*mut T`.
726+
///
727+
/// # Safety
728+
/// Passing an invalid index is undefined behavior.
707729
#[inline(always)]
708730
pub unsafe fn uget_raw<Idx>(&self, index: Idx) -> *mut T
709731
where

src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![allow(clippy::needless_lifetimes)] // We often want to make the GIL lifetime explicit.
2-
#![allow(clippy::missing_safety_doc)] // FIXME
3-
41
//! `rust-numpy` provides Rust interfaces for [NumPy C APIs](https://numpy.org/doc/stable/reference/c-api),
52
//! especially for [ndarray](https://numpy.org/doc/stable/reference/arrays.ndarray.html) class.
63
//!
@@ -30,6 +27,8 @@
3027
//! })
3128
//! }
3229
//! ```
30+
#![allow(clippy::needless_lifetimes)] // We often want to make the GIL lifetime explicit.
31+
3332
pub mod array;
3433
pub mod convert;
3534
mod dtype;

src/npyffi/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
//! Low-Level bindings for NumPy C API.
22
//!
33
//! <https://numpy.org/doc/stable/reference/c-api>
4-
#![allow(non_camel_case_types, clippy::too_many_arguments)]
4+
#![allow(
5+
non_camel_case_types,
6+
clippy::too_many_arguments,
7+
clippy::missing_safety_doc
8+
)]
59

610
use pyo3::{ffi, Python};
711
use std::ffi::CString;

0 commit comments

Comments
 (0)