Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
- os: ubuntu-latest
cargo-features-flag: "--features libc_platform"

timeout-minutes: 20
timeout-minutes: 40
runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
Expand Down
2 changes: 2 additions & 0 deletions doc/release-notes/iceoryx2-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
[#1021](https://github.com/eclipse-iceoryx/iceoryx2/issues/1021)
* Implement `Copy` for `StaticString`, `SemanticString` and system types
[#1114](https://github.com/eclipse-iceoryx/iceoryx2/issues/1114)
* Support `unions` with `ZeroCopySend`
[#1144](https://github.com/eclipse-iceoryx/iceoryx2/issues/1144)

### Bugfixes

Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ These types are demonstrated in the complex data types example.

| Name | Language | Description |
| ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| blackboard | [Rust](rust/blackboard) | Unidirectional communication where one writer updates data in an inter-process key-value store, called the blackboard, which several readers can read. |
| blackboard | [C](c/blackboard) [C++](cxx/blackboard) [Rust](rust/blackboard) | Unidirectional communication where one writer updates data in an inter-process key-value store, called the blackboard, which several readers can read. |
| blackboard_event_based_communication | [Rust](rust/blackboard_event_based_communication) | Updating an inter-process key-value store, called the blackboard, where a writer sends notifications whenever a value is updated. |
| complex data types | [C++](cxx/complex_data_types) [Rust](rust/complex_data_types) | Send zero-copy compatible versions of `Vec` and `String`. Introduces `PlacementDefault` trait for large data types to perform an in place initialization where otherwise a stack overflow would be encountered. |
| cross language communication basics | [C](c/cross_language_communication_basics) [C++](cxx/cross_language_communication_basics) [Python](python/cross_language_communication_basics) [Rust](rust/cross_language_communication_basics) | Cross-language communication between multiple Rust, Python, C++ and C processes with a [publish subscribe messaging pattern](https://en.wikipedia.org/wiki/Publish–subscribe_pattern). |
Expand Down
19 changes: 16 additions & 3 deletions iceoryx2-bb/derive-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,22 @@ pub fn zero_copy_send_derive(input: TokenStream) -> TokenStream {
#type_name_impl
}
}
_ => {
return quote! {compile_error!("ZeroCopySend can only be implemented for structs and enums");}
.into();
Data::Union(ref data_union) => {
let field_inits = data_union.fields.named.iter().map(|f| {
let field_name = &f.ident;
// dummy call to ensure at compile-time that all fields of the union implement ZeroCopySend
quote! {
ZeroCopySend::__is_zero_copy_send(unsafe { &self.#field_name });
}
});

quote! {
fn __is_zero_copy_send(&self) {
#(#field_inits)*
}

#type_name_impl
}
}
};

Expand Down
44 changes: 44 additions & 0 deletions iceoryx2-bb/derive-macros/src/zero_copy_send_compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,47 @@ fn zero_copy_send_derive_does_not_work_for_generic_enum_when_members_do_not_impl
/// ```
#[cfg(doctest)]
fn zero_copy_send_derive_does_not_work_for_generic_enum_when_not_all_members_implement_it() {}

/// === Unions ===

/// ``` compile_fail
/// use iceoryx2_bb_derive_macros::ZeroCopySend;
///
/// struct Foo(u16);
///
/// #[repr(C)]
/// #[derive(ZeroCopySend)]
/// union SomeUnion {
/// val1: u64,
/// val2: Foo,
/// }
/// ```
#[cfg(doctest)]
fn zero_copy_send_derive_does_not_work_for_union_when_not_all_members_implement_it() {}

/// ``` compile_fail
/// use iceoryx2_bb_derive_macros::ZeroCopySend;
///
/// #[repr(C)]
/// #[derive(ZeroCopySend)]
/// union GenericUnion<T1, T2> {
/// val1: T1,
/// val2: T2,
/// }
/// ```
#[cfg(doctest)]
fn zero_copy_send_derive_does_not_work_for_generic_union_when_members_do_not_implement_it() {}

/// ``` compile_fail
/// use iceoryx2_bb_derive_macros::ZeroCopySend;
/// use iceoryx2_bb_elementary_traits::zero_copy_send::ZeroCopySend;
///
/// #[repr(C)]
/// #[derive(ZeroCopySend)]
/// union GenericUnion<T1: ZeroCopySend, T2> {
/// val1: T1,
/// val2: T2,
/// }
/// ```
#[cfg(doctest)]
fn zero_copy_send_derive_does_not_work_for_generic_union_when_not_all_members_implement_it() {}
15 changes: 15 additions & 0 deletions iceoryx2-bb/derive-macros/tests/zero_copy_send_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ mod zero_copy_send {
T1: ZeroCopySend,
T2: ZeroCopySend;

#[repr(C)]
#[derive(ZeroCopySend)]
#[type_name("TryMadHoney")]
union BasicUnionTest {
_val1: u32,
_val2: u8,
}

#[test]
fn zero_copy_send_derive_works_for_named_struct() {
let sut = NamedTestStruct {
Expand Down Expand Up @@ -172,4 +180,11 @@ mod zero_copy_send {
assert_that!(is_zero_copy_send(&sut_with_attr), eq true);
assert_that!(unsafe { GenericUnnamedTestStructWithAttr::<i32, i32>::type_name() }, eq "Smeik");
}

#[test]
fn zero_copy_send_derive_for_unions() {
let sut = BasicUnionTest { _val1: 12 };
assert_that!(is_zero_copy_send(&sut), eq true);
assert_that!(unsafe { BasicUnionTest::type_name() }, eq "TryMadHoney");
}
}
2 changes: 1 addition & 1 deletion iceoryx2-bb/elementary/src/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl BaseAllocator for BumpAllocator {

unsafe {
Ok(core::ptr::NonNull::new_unchecked(
core::slice::from_raw_parts_mut(
core::ptr::slice_from_raw_parts_mut(
self.start.add(mem - self.start as usize),
layout.size(),
),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2-bb/memory/src/bump_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl BaseAllocator for BumpAllocator {
}

Ok(unsafe {
NonNull::new_unchecked(core::slice::from_raw_parts_mut(
NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(
(self.start + aligned_position) as *mut u8,
layout.size(),
))
Expand Down
11 changes: 6 additions & 5 deletions iceoryx2-bb/memory/src/one_chunk_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ impl BaseAllocator for OneChunkAllocator {

self.allocated_chunk_start
.store(adjusted_start, Ordering::Relaxed);
Ok(NonNull::new(unsafe {
core::slice::from_raw_parts_mut(adjusted_start as *mut u8, available_size)
})
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
adjusted_start as *mut u8,
available_size,
))
.unwrap())
}

Expand Down Expand Up @@ -149,7 +150,7 @@ impl Allocator for OneChunkAllocator {
"{} since the size of {} exceeds the available memory size of {}.", msg, new_layout.size(), available_size);
}

Ok(NonNull::new(core::slice::from_raw_parts_mut(
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
ptr.as_ptr(),
available_size,
))
Expand All @@ -175,7 +176,7 @@ impl Allocator for OneChunkAllocator {
"{} since this allocator does not support to any alignment increase in this operation.", msg);
}

Ok(NonNull::new(core::slice::from_raw_parts_mut(
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
ptr.as_ptr(),
new_layout.size(),
))
Expand Down
6 changes: 3 additions & 3 deletions iceoryx2-bb/memory/src/pool_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl BaseAllocator for PoolAllocator {

match unsafe { self.buckets.acquire_raw_index() } {
Ok(v) => Ok(unsafe {
NonNull::new_unchecked(core::slice::from_raw_parts_mut(
NonNull::new_unchecked(core::ptr::slice_from_raw_parts_mut(
(self.start + v as usize * self.bucket_size) as *mut u8,
layout.size(),
))
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Allocator for PoolAllocator {
"{} since the new size {} exceeds the maximum supported size.", msg, new_layout.size());
}

Ok(NonNull::new(core::slice::from_raw_parts_mut(
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
ptr.as_ptr(),
new_layout.size(),
))
Expand Down Expand Up @@ -275,7 +275,7 @@ impl Allocator for PoolAllocator {
"{} since the new alignment {} exceeds the maximum supported alignment.", msg, new_layout.align() );
}

Ok(NonNull::new(core::slice::from_raw_parts_mut(
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
ptr.as_ptr(),
new_layout.size(),
))
Expand Down
7 changes: 4 additions & 3 deletions iceoryx2-bb/posix/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ pub mod heap {
let aligned_start = align(addr + MEMORY_START_STORAGE_SPACE, layout.align());
unsafe { *(aligned_start as *mut usize).offset(-1) = addr };

Ok(NonNull::new(unsafe {
core::slice::from_raw_parts_mut(aligned_start as *mut u8, layout.size())
})
Ok(NonNull::new(core::ptr::slice_from_raw_parts_mut(
aligned_start as *mut u8,
layout.size(),
))
.unwrap())
}

Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/active_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ impl<
>::new_unchecked(
header_ptr,
user_header_ptr,
core::slice::from_raw_parts_mut(
core::ptr::slice_from_raw_parts_mut(
chunk.payload.cast(),
underlying_number_of_slice_elements,
),
Expand Down
4 changes: 2 additions & 2 deletions iceoryx2/src/pending_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl<
RawSample::new_slice_unchecked(
chunk.header.cast(),
chunk.user_header.cast(),
core::slice::from_raw_parts(
core::ptr::slice_from_raw_parts(
chunk.payload.cast::<ResponsePayload>(),
header.number_of_elements() as _,
),
Expand Down Expand Up @@ -441,7 +441,7 @@ impl<
RawSample::new_slice_unchecked(
chunk.header.cast(),
chunk.user_header.cast(),
core::slice::from_raw_parts(
core::ptr::slice_from_raw_parts(
chunk.payload.cast::<CustomPayloadMarker>(),
number_of_bytes as _,
),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/port/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ impl<
>::new_unchecked(
header_ptr,
user_header_ptr,
core::slice::from_raw_parts_mut(
core::ptr::slice_from_raw_parts_mut(
chunk.payload.cast(),
underlying_number_of_slice_elements,
),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/port/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ impl<
RawSampleMut::new_unchecked(
header_ptr,
user_header_ptr,
core::slice::from_raw_parts_mut(
core::ptr::slice_from_raw_parts_mut(
chunk.payload.cast(),
underlying_number_of_slice_elements,
),
Expand Down
2 changes: 1 addition & 1 deletion iceoryx2/src/port/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ impl<
RawSample::new_slice_unchecked(
chunk.header.cast(),
chunk.user_header.cast(),
core::slice::from_raw_parts(
core::ptr::slice_from_raw_parts(
chunk.payload.cast::<RequestPayload>(),
number_of_elements as _,
),
Expand Down
7 changes: 5 additions & 2 deletions iceoryx2/src/port/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,10 @@ impl<
RawSample::<Header, UserHeader, [Payload]>::new_slice_unchecked(
header_ptr,
chunk.user_header.cast(),
core::slice::from_raw_parts(chunk.payload.cast(), number_of_elements as _),
core::ptr::slice_from_raw_parts(
chunk.payload.cast(),
number_of_elements as _,
),
)
},
}
Expand Down Expand Up @@ -448,7 +451,7 @@ impl<Service: service::Service, UserHeader: Debug + ZeroCopySend>
RawSample::<Header, UserHeader, [CustomPayloadMarker]>::new_slice_unchecked(
header_ptr,
chunk.user_header.cast(),
core::slice::from_raw_parts(chunk.payload.cast(), number_of_bytes),
core::ptr::slice_from_raw_parts(chunk.payload.cast(), number_of_bytes),
)
},
}
Expand Down