Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iox-#1614 Move uninitialized array #1774

Conversation

FerdinandSpitzschnueffler
Copy link
Contributor

@FerdinandSpitzschnueffler FerdinandSpitzschnueffler commented Nov 1, 2022

Pre-Review Checklist for the PR Author

  1. Code follows the coding style of CONTRIBUTING.md
  2. Tests follow the best practice for testing
  3. Changelog updated in the unreleased section including API breaking changes
  4. Branch follows the naming format (iox-123-this-is-a-branch)
  5. Commits messages are according to this guideline
  6. Update the PR title
    • Follow the same conventions as for commit messages
    • Link to the relevant issue
  7. Relevant issues are linked
  8. Add sensible notes for the reviewer
  9. All checks have passed (except task-list-completed)
  10. All touched (C/C++) source code files from iceoryx_hoofs are added to ./clang-tidy-diff-scans.txt
  11. Assign PR to reviewer

Notes for Reviewer

This PR moves the UninitializedArray to iceoryx_hoofs/containers/include/iox/detail/ and removes the namespace containers.

Checklist for the PR Reviewer

  • Commits are properly organized and messages are according to the guideline
  • Code according to our coding style and naming conventions
  • Unit tests have been written for new behavior
  • Public API changes are documented via doxygen
  • Copyright owner are updated in the changed files
  • All touched (C/C++) source code files from iceoryx_hoofs have been added to ./clang-tidy-diff-scans.txt
  • PR title describes the changes

Post-review Checklist for the PR Author

  1. All open points are addressed and tracked via issues

References

@FerdinandSpitzschnueffler FerdinandSpitzschnueffler added refactoring Refactor code without adding features globex labels Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #1774 (bc37c9b) into master (69ed96d) will decrease coverage by 0.03%.
The diff coverage is 91.17%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1774      +/-   ##
==========================================
- Coverage   77.39%   77.35%   -0.04%     
==========================================
  Files         367      367              
  Lines       14245    14243       -2     
  Branches     1992     1992              
==========================================
- Hits        11025    11018       -7     
- Misses       2591     2592       +1     
- Partials      629      633       +4     
Flag Coverage Δ
unittests 77.01% <91.17%> (-0.04%) ⬇️
unittests_timing 15.64% <23.52%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../include/iceoryx_dust/posix_wrapper/named_pipe.hpp 100.00% <ø> (ø)
...ntainer/include/iox/detail/uninitialized_array.inl 100.00% <ø> (ø)
...oofs/container/include/iox/uninitialized_array.hpp 100.00% <ø> (ø)
iceoryx_hoofs/include/iceoryx_hoofs/cxx/stack.hpp 100.00% <ø> (ø)
iceoryx_hoofs/include/iceoryx_hoofs/cxx/string.hpp 100.00% <ø> (ø)
...ceoryx_hoofs/include/iceoryx_hoofs/cxx/variant.hpp 100.00% <ø> (ø)
iceoryx_hoofs/include/iceoryx_hoofs/cxx/vector.hpp 100.00% <ø> (ø)
...include/iceoryx_hoofs/internal/concurrent/sofi.hpp 100.00% <ø> (ø)
...include/iceoryx_hoofs/posix_wrapper/posix_call.hpp 100.00% <ø> (ø)
...oryx_hoofs/source/posix_wrapper/access_control.cpp 64.70% <ø> (ø)
... and 7 more

elfenpiff
elfenpiff previously approved these changes Nov 1, 2022
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine. Just one question related to the location and it seems bazel is not happy

doc/website/release-notes/iceoryx-unreleased.md Outdated Show resolved Hide resolved
@elBoberido
Copy link
Member

Oh, the clang-tidy warning will disappear once you rebase to master :)

…amespace iox

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
@FerdinandSpitzschnueffler FerdinandSpitzschnueffler force-pushed the iox-1614-move-uninitialized-array branch from 9d905aa to edd3f99 Compare November 1, 2022 16:11
Move header file to iox folder, remove 's' from buffer and container
modules

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
elBoberido
elBoberido previously approved these changes Nov 2, 2022
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the clang-tidy-diff file could be simplified

.clang-tidy-diff-scans.txt Outdated Show resolved Hide resolved
elfenpiff
elfenpiff previously approved these changes Nov 2, 2022
Replace UninitializedArrays with ElementType char with char
array

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
elBoberido
elBoberido previously approved these changes Nov 3, 2022
Refactoring in UninitializedArray, variant and optional. Change gcc
version to 8 for ubuntu build.

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
MatthiasKillat
MatthiasKillat previously approved these changes Nov 7, 2022
Copy link
Contributor

@MatthiasKillat MatthiasKillat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The brace zero initialization question is the only relevant comment. Everything else is only a style question or potential future refactoring in a different issue.

{
// AXIVION Next Construct AutosarC++19_03-A18.1.1 : required by low level UninitializedArray building block and encapsulated in abstraction
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
cxx::byte_t data[sizeof(ElementType)];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding any other fields to the struct will break things. Maybe worth a comment.

I am also wondering whether the zero-initialization braces { } are required here (instead of array of element_t).

alignas(ElementType) element_t value[Capacity]{};
// NOLINTEND(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
// NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
element_t value[Capacity]{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move the braces to element_t, they should not be required here. I am generally not sure how it works with padding without trying it out.

There can be trailing padding in element_t (to make size a multiple of alignment). Depends on our requirements of the padding initialization. Padding initialization which would not happen if we move it I think, but would it as it is now?

@elBoberido FYI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the UninitialiizedArray is typed and element_t uses the size and alignment of that type, there are no issues with additional padding bytes

@@ -229,7 +230,14 @@ class optional final : public FunctionalInterface<optional<T>, T, void>
// initHandle(&handle);
// }
bool m_hasValue{false};
typename std::aligned_storage<sizeof(T), alignof(T)>::type m_data;
struct alignas(T) element_t
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be necessary to use our own struct. Do we want to remove the dependency on std::aligned_storage or is there another reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced std::aligned_storage since it is deprecated in C++23 (I know, not a problem now but maybe later) and already added similar constructs in variant and UninitializedArray.

iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant.hpp Outdated Show resolved Hide resolved
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just a few minor remarks

iceoryx_hoofs/include/iceoryx_hoofs/cxx/variant.hpp Outdated Show resolved Hide resolved
@@ -31,7 +31,7 @@ inline constexpr variant<Types...>::variant(const variant& rhs) noexcept
{
if (m_type_index != INVALID_VARIANT_INDEX)
{
internal::call_at_index<0, Types...>::copyConstructor(m_type_index, rhs.m_storage, m_storage);
internal::call_at_index<0, Types...>::copyConstructor(m_type_index, &rhs.m_storage.data[0], &m_storage.data[0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this leads to warnings with -Wcast-align=strict. Unfortunately this is baked into the call_at_index struct.

Copy link
Member

@elBoberido elBoberido Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FerdinandSpitzschnueffler after some thinking, the call_at_index should use void* instead of byte_t*. Could you please change that?

With that change there is only two offender when using -Wcast_aling=strict

One is in types.h in the C binding. Changing

/// @brief handle of the chunk header
typedef struct
{
    // could be empty but then we get `struct has no members` warning
    uint8_t do_not_touch_me[1];
} iox_chunk_header_t;

to

/// @brief handle of the chunk header
typedef struct iox_chunk_header_opaque_t iox_chunk_header_t;

fixes the problem there.

And the others in the UDS and MQ iceperf code ... which is just by coincidence not broken 😅

I think types.h and the iceperf example could be fixed in another PR.

Copy link
Contributor

@MatthiasKillat MatthiasKillat Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also in another issue, in types.h we may consider defining iox::byte to be char and not uint8_t. This is mainly to prevent some issues with strict aliasing with compilers that do not define uint8_t to be unsigned char (I do not know of such a compiler).

It is mandated by the standard that no type can be smaller than char (and unsigned char I guess), and sizeof(char) = 1. So we do not lose guarantees but prevent some strict aliasing problems on exotic compilers.

To my knowledge, there is no reason to define a byte not to be char instead of uint8_t. Note that C++17 offers std::byte but we cannot use that here, see https://stackoverflow.com/questions/46150738/how-to-use-new-stdbyte-type-in-places-where-old-style-unsigned-char-is-needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed call_at_index to take a void* and created #1778 for the warnings in the C binding and the iceperf example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MatthiasKillat I like the idea of a iox::byte similar to std::byte. Would be something for a separate issue.

…ve .data

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
elBoberido
elBoberido previously approved these changes Nov 7, 2022
Copy link
Member

@elBoberido elBoberido left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My last remark can also be done in a separate PR since it is not really related to the uninitialized array

Signed-off-by: Marika Lehmann <marika.lehmann@apex.ai>
@FerdinandSpitzschnueffler FerdinandSpitzschnueffler merged commit 6a58416 into eclipse-iceoryx:master Nov 8, 2022
@FerdinandSpitzschnueffler FerdinandSpitzschnueffler deleted the iox-1614-move-uninitialized-array branch November 8, 2022 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
globex refactoring Refactor code without adding features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implement uninitialized array
4 participants