Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1900 Refactor byte_t to be a distinct type
Browse files Browse the repository at this point in the history
Signed-off-by: Ziad Mostafa <ziad.mostafa@apex.ai>
  • Loading branch information
Ziad Mostafa committed Feb 20, 2023
1 parent 2f87030 commit e5a15d5
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 13 deletions.
13 changes: 13 additions & 0 deletions doc/website/release-notes/iceoryx-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
- Remove `algorithm::uniqueMergeSortedContainers` from `algorithm.hpp`
- Move `std::string` conversion function to `iceoryx_dust` [\#1612](https://github.com/eclipse-iceoryx/iceoryx/issues/1612)
- The posix call `unlink` is directly used in `UnixDomainSocket` [\#1622](https://github.com/eclipse-iceoryx/iceoryx/issues/1622)
- Make iox::byte_t a distinct type [\#1900](https://github.com/eclipse-iceoryx/iceoryx/issues/1900)

**Workflow:**

Expand Down Expand Up @@ -1021,3 +1022,15 @@
// after
#include "iox/duration.hpp"
```
46. Renaming `byte_t` to `byte`
`byte` is not a simple type alias, now it is a distinct type like c++17 `std::byte`.
The type `byte` does not support any arithmetic operations nor has member functions.

```cpp
//before
iox::byte_t m_size;

//after
iox::byte m_size;
```

2 changes: 1 addition & 1 deletion iceoryx_hoofs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an
| class | internal | description |
|:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|`type_traits` | | Extended support for evaluating types on compile-time. |
|`types` | | Declares essential building block types like `byte_t`. |
|`types` | | Declares essential building block types like `byte`. |
|`attributes` | | C++17 and C++20 attributes are sometimes available through compiler extensions. The attribute macros defined in here (like `IOX_FALLTHROUGH`, `IOX_MAYBE_UNUSED` ... ) make sure that we are able to use them if the compiler supports it. |
|`algorithm` | | Implements `min` and `max` for an arbitrary number of values of the same type. For instance `min(1,2,3,4,5);` |
|`size` | | Helper functions to determine the size in generic ways |
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/container/include/iox/uninitialized_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ZeroedBuffer
{
// AXIVION Next Construct AutosarC++19_03-A18.1.1, AutosarC++19_03-M0.1.3 : required by low level UninitializedArray building block and encapsulated in abstraction, declaration of field in struct for usage elsewhere
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
byte_t data[sizeof(ElementType)];
byte data[sizeof(ElementType)];
};
// AXIVION Next Construct AutosarC++19_03-A18.1.1, AutosarC++19_03-A1.1.1 : required by low level UninitializedArray building block and encapsulated in abstraction, object size limit is not relevant for containers stored in shared memory.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
Expand All @@ -52,7 +52,7 @@ struct NonZeroedBuffer
{
// AXIVION Next Construct AutosarC++19_03-A18.1.1, AutosarC++19_03-M0.1.3 : required by low level UninitializedArray building block and encapsulated in abstraction, declaration of field in struct for usage elsewhere
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
byte_t data[sizeof(ElementType)];
byte data[sizeof(ElementType)];
};
// AXIVION Next Construct AutosarC++19_03-A18.1.1, AutosarC++19_03-A1.1.1 : required by low level UninitializedArray building block and encapsulated in abstraction, object size limit is not relevant for containers stored in shared memory
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class storable_function<Capacity, signature<ReturnType, Args...>> final

// AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the storable_function
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
byte_t m_storage[Capacity]; // storage for the callable
byte m_storage[Capacity]; // storage for the callable
void* m_callable{nullptr}; // pointer to stored type-erased callable
ReturnType (*m_invoker)(void*, Args&&...){nullptr}; // indirection to invoke the stored callable,
// nullptr if no callable is stored
Expand Down Expand Up @@ -195,7 +195,7 @@ class storable_function<Capacity, signature<ReturnType, Args...>> final
static ReturnType invokeFreeFunction(void* callable, Args&&... args) noexcept;

template <typename T>
static constexpr void* safeAlign(byte_t* startAddress);
static constexpr void* safeAlign(byte* startAddress);
};

/// @brief swap two storable functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ inline void swap(storable_function<Capacity, T>& f, storable_function<Capacity,

template <uint64_t Capacity, typename ReturnType, typename... Args>
template <typename T>
inline constexpr void* storable_function<Capacity, signature<ReturnType, Args...>>::safeAlign(byte_t* startAddress)
inline constexpr void* storable_function<Capacity, signature<ReturnType, Args...>>::safeAlign(byte* startAddress)
{
static_assert(is_storable<T>(), "type does not fit into storage");
// NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast, performance-no-int-to-ptr) required for low level pointer alignment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace iox
{
namespace posix
{
using byte_t = uint8_t;

enum class SharedMemoryObjectError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ namespace iox
/// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/iceoryx_hoofs_types.hpp' instead")]]
namespace cxx
{
/// @deprecated use `iox::byte_t` instead of `iox::cxx::byte_t`
using iox::byte_t;
/// @deprecated use `iox::byte` instead of `iox::cxx::byte_t`
using byte_t = byte;

} // namespace cxx
namespace log
{
Expand Down
5 changes: 4 additions & 1 deletion iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@

namespace iox
{
using byte_t = uint8_t;

enum class byte : uint8_t
{
};

// AXIVION Next Construct AutosarC++19_03-M2.10.1 : log is a sensible namespace for a logger; furthermore it is in the
// iox namespace and when used as function the compiler will complain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct is_in_place_type<in_place_type<T>> : std::true_type
{
};

using byte_t = uint8_t;
template <typename TypeToCheck, typename T, typename... Targs>
struct does_contain_type
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/vocabulary/include/iox/optional.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class optional final : public FunctionalInterface<optional<T>, T, void>
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the array
// is wrapped inside the optional
// NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
byte_t data[sizeof(T)];
byte data[sizeof(T)];
};
element_t m_data;

Expand Down
3 changes: 2 additions & 1 deletion iceoryx_hoofs/vocabulary/include/iox/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "iox/algorithm.hpp"
#include "iox/detail/variant_internal.hpp"
#include "iox/iceoryx_hoofs_types.hpp"

#include <cstdint>
#include <iostream>
Expand Down Expand Up @@ -265,7 +266,7 @@ class variant final
// AXIVION Next Construct AutosarC++19_03-M0.1.3 : data provides the actual storage and is accessed via m_storage since &m_storage.data = &m_storage
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the variant class
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays)
internal::byte_t data[TYPE_SIZE];
iox::byte data[TYPE_SIZE];
};
storage_t m_storage{};
uint64_t m_type_index{INVALID_VARIANT_INDEX};
Expand Down

0 comments on commit e5a15d5

Please sign in to comment.