Skip to content

Commit 71a82a3

Browse files
authored
Merge pull request #469 from Icxolu/sync
make `PySliceContainer` implement `Sync`
2 parents 0f1dd03 + 82d0466 commit 71a82a3

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/dtype.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl Sealed for Bound<'_, PyArrayDescr> {}
697697
///
698698
/// [enumerated-types]: https://numpy.org/doc/stable/reference/c-api/dtype.html#enumerated-types
699699
/// [data-models]: https://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models
700-
pub unsafe trait Element: Sized + Send {
700+
pub unsafe trait Element: Sized + Send + Sync {
701701
/// Flag that indicates whether this type is trivially copyable.
702702
///
703703
/// It should be set to true for all trivially copyable types (like scalar types

src/slice_container.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,17 @@ pub(crate) struct PySliceContainer {
1313
drop: unsafe fn(*mut u8, usize, usize),
1414
}
1515

16+
// This resembles `unsafe impl<T: Send> Send for PySliceContainer<T> {}` if we
17+
// were allow to use a generic there.
18+
// SAFETY: Every construction below enforces `T: Send` fulfilling the ideal bound above
1619
unsafe impl Send for PySliceContainer {}
1720

18-
impl<T: Send> From<Box<[T]>> for PySliceContainer {
21+
// This resembles `unsafe impl<T: Sync> Sync for PySliceContainer<T> {}` if we
22+
// were allow to use a generic there.
23+
// SAFETY: Every construction below enforces `T: Sync` fulfilling the ideal bound above
24+
unsafe impl Sync for PySliceContainer {}
25+
26+
impl<T: Send + Sync> From<Box<[T]>> for PySliceContainer {
1927
fn from(data: Box<[T]>) -> Self {
2028
unsafe fn drop_boxed_slice<T>(ptr: *mut u8, len: usize, _cap: usize) {
2129
let _ = Box::from_raw(ptr::slice_from_raw_parts_mut(ptr as *mut T, len));
@@ -39,7 +47,7 @@ impl<T: Send> From<Box<[T]>> for PySliceContainer {
3947
}
4048
}
4149

42-
impl<T: Send> From<Vec<T>> for PySliceContainer {
50+
impl<T: Send + Sync> From<Vec<T>> for PySliceContainer {
4351
fn from(data: Vec<T>) -> Self {
4452
unsafe fn drop_vec<T>(ptr: *mut u8, len: usize, cap: usize) {
4553
let _ = Vec::from_raw_parts(ptr as *mut T, len, cap);
@@ -65,7 +73,7 @@ impl<T: Send> From<Vec<T>> for PySliceContainer {
6573

6674
impl<A, D> From<ArrayBase<OwnedRepr<A>, D>> for PySliceContainer
6775
where
68-
A: Send,
76+
A: Send + Sync,
6977
D: Dimension,
7078
{
7179
fn from(data: ArrayBase<OwnedRepr<A>, D>) -> Self {

0 commit comments

Comments
 (0)