Skip to content

Conversation

@pjungkamp
Copy link
Contributor

I've gone through our utils.hpp header and removed macros and functions that map directly to the standard library.

Each change is a separate commit and can be dropped if deemed undesirable.

Almost all changes could be done using simple automation like e.g. replacing ARRAY_LEN with std::size.

The standard library alternatives often provide stronger type safety and prevent subtle bugs.

  • Using ARRAY_LEN on a decayed pointer to an array would just return 1, while std::size only works for non-decayed arrays or library containers.
  • std::swap will respect ADL swap specializations which may elide unneccessary copies.
  • std::min and std::max don't compile if the participating integer types differ. This forces us to highlight narrowing integer conversions with an explicit static_cast, instead of an implicit truncation. (We are often mixing size_t and unsigned int lengths)
  • C++20 introduced the <bit> header which has functions replacing macros like IS_POW2/LOG2_CEIL
  • Some macros and functions were unused or used only once.

Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
@pjungkamp
Copy link
Contributor Author

pjungkamp commented Feb 10, 2026

The test failure in the CI is actually really interesting. The cause is the commit replacing LOG2_CEIL with std::bit_ceil.

LOG2_CEIL is a somewhat obscure name; it's supposed to calculate the next power of two not lower than the argument, but it's absolutely broken for x <= 1.

x LOG2_CEIL(x) std::bit_ceil(x)
0 undefined 1
1 4 1
2 2 2
3 4 4
4 4 4

https://godbolt.org/z/r1r6j3fP8

This breaks code which was implicitly relying on LOG2_CEIL(1) returning a value greater than 1.

@pjungkamp
Copy link
Contributor Author

Ok, the problem is that the villas-pipe sample pool now has a capacity of 1 instead of 4, but the implicitly instantiated drop and restart hooks hold a reference on the previous sample, which means that the receiving end of villas-pipe will exhaust its sample pool after the first sample has been processed.

What would be the correct way to fix this? We don't have any metadata about how many samples may be buffered during processing. I see two possible fixes here:

  • Add a constant to the pool size.
  • Make the pool size at least 3.

Signed-off-by: Philipp Jungkamp <philipp.jungkamp@rwth-aachen.de>
Copy link
Contributor

@stv0g stv0g left a comment

Choose a reason for hiding this comment

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

Great work! This is really a good example of how a PR should be structured and presented!

A pleasure to review :)

@stv0g stv0g merged commit f4538b2 into master Feb 10, 2026
3 checks passed
@stv0g stv0g deleted the utils-cleanup branch February 10, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants