diff --git a/src/dtype.rs b/src/dtype.rs index b6cbea0b..e22ac20a 100644 --- a/src/dtype.rs +++ b/src/dtype.rs @@ -697,7 +697,7 @@ impl Sealed for Bound<'_, PyArrayDescr> {} /// /// [enumerated-types]: https://numpy.org/doc/stable/reference/c-api/dtype.html#enumerated-types /// [data-models]: https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models -pub unsafe trait Element: Sized + Send { +pub unsafe trait Element: Sized + Send + Sync { /// Flag that indicates whether this type is trivially copyable. /// /// It should be set to true for all trivially copyable types (like scalar types diff --git a/src/slice_container.rs b/src/slice_container.rs index b1326746..0c29eae6 100644 --- a/src/slice_container.rs +++ b/src/slice_container.rs @@ -13,9 +13,17 @@ pub(crate) struct PySliceContainer { drop: unsafe fn(*mut u8, usize, usize), } +// This resembles `unsafe impl Send for PySliceContainer {}` if we +// were allow to use a generic there. +// SAFETY: Every construction below enforces `T: Send` fulfilling the ideal bound above unsafe impl Send for PySliceContainer {} -impl From> for PySliceContainer { +// This resembles `unsafe impl Sync for PySliceContainer {}` if we +// were allow to use a generic there. +// SAFETY: Every construction below enforces `T: Sync` fulfilling the ideal bound above +unsafe impl Sync for PySliceContainer {} + +impl From> for PySliceContainer { fn from(data: Box<[T]>) -> Self { unsafe fn drop_boxed_slice(ptr: *mut u8, len: usize, _cap: usize) { let _ = Box::from_raw(ptr::slice_from_raw_parts_mut(ptr as *mut T, len)); @@ -39,7 +47,7 @@ impl From> for PySliceContainer { } } -impl From> for PySliceContainer { +impl From> for PySliceContainer { fn from(data: Vec) -> Self { unsafe fn drop_vec(ptr: *mut u8, len: usize, cap: usize) { let _ = Vec::from_raw_parts(ptr as *mut T, len, cap); @@ -65,7 +73,7 @@ impl From> for PySliceContainer { impl From, D>> for PySliceContainer where - A: Send, + A: Send + Sync, D: Dimension, { fn from(data: ArrayBase, D>) -> Self {