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

Fix IPAddress packed layout and iovector flex array #352

Merged
merged 2 commits into from
Feb 6, 2024

Conversation

Coldwings
Copy link
Collaborator

@Coldwings Coldwings commented Feb 6, 2024

In issue #350

Shows new version GCC performs more check for old GNU extensions, and treats union as non-POD member in struct layout.

Here some fixes for them, tested worked in GCC 13.2 and fits the requirements of C++ standard:

  1. Use flex array instead of deprecated zero-sized array which causes warning.
  2. Prevent inherent to a struct with flex-array.
  3. Add attribute for union in IPAddr, make IPAddr struct able to be packed

@Coldwings Coldwings requested review from lihuiba and beef9999 February 6, 2024 06:48
@Coldwings Coldwings changed the title Release/0.7 Fix IPAddress packed layout and iovector flex array Feb 6, 2024
@@ -827,7 +828,7 @@ class iovector
uint16_t capacity; // total capacity
uint16_t iov_begin, iov_end; // [iov_begin, iov_end)
uint16_t nbases; // # of allocated pointers
struct iovec iovs[0];
Copy link
Collaborator

@lihuiba lihuiba Feb 6, 2024

Choose a reason for hiding this comment

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

[0] is a common practice, and it's more read-able than iovs_ptr(). We can simple ignore the warning with #pragma.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a common solution in GNU C extension.
C99 standard add new define of flex array, struct iovec iovs[] to present a flex array.
though, C++ does not allow inheritance by a class with tailed flex array, that is why here replaced by iovs_ptr()

Seems there is not a better solution than iovs[0]

@lihuiba lihuiba merged commit 1bf5242 into alibaba:release/0.7 Feb 6, 2024
7 checks passed
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