Skip to content

Commit

Permalink
Require Send+Sync bounds for Allocation trait (apache#1945)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann authored Jun 26, 2022
1 parent 9f7b600 commit 55d6073
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions arrow/src/alloc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 0 additions & 5 deletions arrow/src/buffer/immutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions arrow/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 55d6073

Please sign in to comment.