-
Notifications
You must be signed in to change notification settings - Fork 923
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 warnings issued by -Wpadded (gcc/clang). #151
Conversation
This is a duplicate of #118, where the state is "we'll take a patch, but it's got to preserve ABI compatibility somehow." |
Hm... I'm not sure about the progress in #118. 😕 However, if understood well, a possible way to fix it would be adding a |
Hey dude, what do you think about to add |
I think this patch would be improved by your adding |
The commit 93d1dfc adds the |
@@ -1172,10 +1176,16 @@ typedef struct UT_hash_bucket { | |||
|
|||
typedef struct UT_hash_table { | |||
UT_hash_bucket *buckets; | |||
#ifdef DUTHASH_V2_ABI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why you did this, but actually I meant UTHASH_V2_ABI
to be the current/old ABI (because the current uthash version number is 2.x). Anyway, I've got a more future-proof(?) idea now:
#ifndef UTHASH_ABI_VERSION
#define UTHASH_ABI_VERSION 3
#endif
#if UTHASH_ABI_VERSION >= 3
tail, hho, num_buckets, log2_num_buckets, num_items
#else
num_buckets, log2_num_buckets, num_items, tail, hho
#endif
This would make it easier to jump again to V4, V5,... if we needed to, while ensuring that anyone who needed ABI stability would only ever have to learn one pattern: -DUTHASH_ABI_VERSION=(whatever today's major version number is)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 for UTHASH_ABI_VERSION
. We should upgrade the UTHASH_VERSION
to 3.0.0
too, what do you thing?
struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ | ||
ptrdiff_t hho; /* hash handle offset (byte pos of hash handle in element */ | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as you're changing the struct layout, I wonder whether we should add explicit "padding" fields at the end of the struct, since (with the Bloom filter) it currently contains 8x+5 bytes in the 32-bit case and 8x+1 bytes in the 64-bit case. But I worry that the same people complaining about the difference between 56 bytes and 64 bytes might just as well start complaining about not being able to store things in the tail-padding of this struct. 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you thing about to declare two entire separated structs? For example:
#if UTHASH_ABI_VERSION >= 3
typedef struct UT_hash_table {
all >=3 members ...
}
#else
typedef struct UT_hash_table {
all <=2 members ...
}
#endif
Using -Werror=padded/-Wpadded
we can't declare tail/hho
as tail in the struct because error "padding struct to align ‘tail’
".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "tail-padding", I meant "padding after the last member of the struct whatever it is," not "padding before/after the member whose name is tail
."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understood "padding after the last member of the struct whatever it is" correct, but it compiles:
gcc main.c
main.c
struct foo {
int a;
char *b;
};
int main() {
struct foo bar;
printf("%zd - %zd\n", sizeof(bar.a), sizeof(bar.b));
return 0;
}
it raises error at compile time (because b
is larger than a
):
gcc -Wpadded main.c
main.c:5:11: error: padding struct to align ‘b’ [-Wpadded]
char *b;
^
cc1: some warnings being treated as errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GCC/Clang has the attribute __attribute__((packed))
, but I'm not attribute expert so I don't know any performance impact by adding such option in the uthash struct. Anyway, the following code compiles fine even using -Wpadded
:
typedef struct
#if UTHASH_ABI_VERSION >= 3
__attribute__((packed))
#endif
UT_hash_table {
UT_hash_bucket *buckets;
unsigned num_buckets, log2_num_buckets, num_items;
struct UT_hash_handle *tail;
ptrdiff_t hho;
unsigned ideal_chain_maxlen;
...
} UT_hash_table;
Hello @Quuxplusone . It seems the |
Christian Grothoff is blunter than I am, but I think he's got essentially the right attitude on this one. 😛 |
Hehehe |
This PR fixes the following errors (passing
-Wall -Werror -Wextra -Wpedantic -Wpadded
):