This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 55d60730d Require Send+Sync bounds for Allocation trait (#1945)
55d60730d is described below
commit 55d60730d287ac66314f7c3801a5e8bb4fc7a2d5
Author: Jörn Horstmann <[email protected]>
AuthorDate: Sun Jun 26 23:18:05 2022 +0200
Require Send+Sync bounds for Allocation trait (#1945)
---
arrow/src/alloc/mod.rs | 4 ++--
arrow/src/buffer/immutable.rs | 5 -----
arrow/src/bytes.rs | 5 +++++
arrow/src/ffi.rs | 3 +++
4 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/arrow/src/alloc/mod.rs b/arrow/src/alloc/mod.rs
index 418bc95fd..526850685 100644
--- a/arrow/src/alloc/mod.rs
+++ b/arrow/src/alloc/mod.rs
@@ -127,9 +127,9 @@ pub unsafe fn reallocate<T: NativeType>(
/// The owner of an allocation.
/// The trait implementation is responsible for dropping the allocations once
no more references exist.
-pub trait Allocation: RefUnwindSafe {}
+pub trait Allocation: RefUnwindSafe + Send + Sync {}
-impl<T: RefUnwindSafe> Allocation for T {}
+impl<T: RefUnwindSafe + Send + Sync> Allocation for T {}
/// Mode of deallocating memory regions
pub(crate) enum Deallocation {
diff --git a/arrow/src/buffer/immutable.rs b/arrow/src/buffer/immutable.rs
index f5d59c5ed..cb686bd84 100644
--- a/arrow/src/buffer/immutable.rs
+++ b/arrow/src/buffer/immutable.rs
@@ -257,11 +257,6 @@ impl std::ops::Deref for Buffer {
}
}
-unsafe impl Sync for Buffer {}
-// false positive, see https://github.com/apache/arrow-rs/pull/1169
-#[allow(clippy::non_send_fields_in_send_ty)]
-unsafe impl Send for Buffer {}
-
impl From<MutableBuffer> for Buffer {
#[inline]
fn from(buffer: MutableBuffer) -> Self {
diff --git a/arrow/src/bytes.rs b/arrow/src/bytes.rs
index 7b57552e6..75137a552 100644
--- a/arrow/src/bytes.rs
+++ b/arrow/src/bytes.rs
@@ -101,6 +101,11 @@ impl Bytes {
}
}
+// Deallocation is Send + Sync, repeating the bound here makes that
refactoring safe
+// The only field that is not automatically Send+Sync then is the NonNull ptr
+unsafe impl Send for Bytes where Deallocation: Send {}
+unsafe impl Sync for Bytes where Deallocation: Sync {}
+
impl Drop for Bytes {
#[inline]
fn drop(&mut self) {
diff --git a/arrow/src/ffi.rs b/arrow/src/ffi.rs
index 84905af20..9be20ccd6 100644
--- a/arrow/src/ffi.rs
+++ b/arrow/src/ffi.rs
@@ -409,6 +409,9 @@ impl Drop for FFI_ArrowArray {
}
}
+unsafe impl Send for FFI_ArrowArray {}
+unsafe impl Sync for FFI_ArrowArray {}
+
// callback used to drop [FFI_ArrowArray] when it is exported
unsafe extern "C" fn release_array(array: *mut FFI_ArrowArray) {
if array.is_null() {